Staubfinger
da1023fcc5
AK: Add thresholds to quickselect_inline
and Statistics::Median
...
I did a bit of Profiling and made the quickselect and median algorithms
use the best of option for the respective input size.
2023-02-03 19:04:15 +01:00
Staubfinger
6b9344e86c
AK: Use AK:quickselect_inline
to compute AK::Statistics::median
...
Quick select is an algorithm that is able to find the median
of a Vector without fully sorting it.
This replaces the old very naive implementation
for `AK::Statistics::median()` with `AK::quickselect_inline`
2023-02-03 19:04:15 +01:00
Staubfinger
607441de56
AK: Implement the quick select algorithm as AK::quickselect_inplace
...
This adds the quick select algorithm that finds
the kth smallest element for any collection.
Whilst doing so it also partially sorts the collection.
I have also included the option to use different pivoting functions
including median of medians which makes the quick select have
a truely linear time complexity at the costs of enormous overhead,
so this that only really useful for really large datasets.
The same was chosen to reflect the fact that it modifies
the collection in place during the selection process.
2023-02-03 19:04:15 +01:00
Sam Atkins
7d0529b89c
AK: Remove JsonObject::get_deprecated() and ::get_ptr() :^)
2023-02-03 07:19:52 -05:00
Timothy Flynn
2af7447dfd
AK: Define HashMap::take to find and remove a value from the map
2023-02-02 19:14:00 +00:00
Timothy Flynn
f31bd190b0
AK: Ensure string types are actually considered hash-compatible
...
The AnyString concept is currently broken because it checks whether a
StringView is constructible from a type T. The StringView constructors,
however, only accept constant rvalue references - i.e. `T const&`.
This also adds a test to ensure this continues to work.
2023-02-02 19:14:00 +00:00
Timothy Flynn
2f67f2ba3d
AK: Return a constant reference from HashMap's constant get() override
...
We cannot return a mutable reference from a constant function.
2023-02-02 19:14:00 +00:00
Ben Wiederhake
e147d0b572
AK: Fix all quadratic-time append-loops over ByteBuffer
2023-01-31 16:58:25 +01:00
Iman Seyed
0ebcc99e12
AK: Remove unused network ordered 'address' variable
2023-01-31 12:42:49 +01:00
Tim Schumacher
093cf428a3
AK: Move memory streams from LibCore
2023-01-29 19:16:44 -07:00
Tim Schumacher
22f0d04f43
AK: Provide a fallback definition for std::nothrow
2023-01-29 19:16:44 -07:00
Tim Schumacher
2470dd3bb5
AK: Move bit streams from LibCore
2023-01-29 19:16:44 -07:00
Tim Schumacher
94f139c111
AK: Move buffered streams from LibCore
2023-01-29 19:16:44 -07:00
Tim Schumacher
8464da1439
AK: Move Stream
and SeekableStream
from LibCore
...
`Stream` will be qualified as `AK::Stream` until we remove the
`Core::Stream` namespace. `IODevice` now reuses the `SeekMode` that is
defined by `SeekableStream`, since defining its own would require us to
qualify it with `AK::SeekMode` everywhere.
2023-01-29 19:16:44 -07:00
Tim Schumacher
5f2ea31816
AK: Move Handle
from LibCore
and name it MaybeOwned
...
The new name should make it abundantly clear what it does.
2023-01-29 19:16:44 -07:00
Tim Schumacher
5fa590de71
AK: Remove Buffered
2023-01-29 19:16:44 -07:00
Tim Schumacher
ae64b68717
AK: Deprecate the old AK::Stream
...
This also removes a few cases where the respective header wasn't
actually required to be included.
2023-01-29 19:16:44 -07:00
Andreas Kling
230cb3b0cb
AK: Add DeprecatedString::from_utf8()
...
This will be used in Jakt to help transition off of DeprecatedString.
2023-01-29 23:41:42 +01:00
Andreas Kling
6b497b8710
AK: Add two helpers to DeprecatedStringCodePointIterator
2023-01-29 23:41:42 +01:00
Linus Groh
9c08bb9555
AK: Remove try_
prefix from FixedArray creation functions
2023-01-28 22:41:36 +01:00
Timothy Flynn
e96c64cdb4
AK: Add support for the new FlyString to StringView
2023-01-28 15:24:55 +00:00
Timothy Flynn
b61f8cd130
AK: Delete the StringView move-assignment operator for various types
2023-01-28 15:24:55 +00:00
Andreas Kling
2dc657c77e
AK: Add DeprecatedStringCodePointIterator
...
This is a safe iterator over the underlying code points. It will be used
in Jakt to assist in the migration away from DeprecatedString.
2023-01-28 09:50:52 +01:00
Timothy Flynn
c59268d15b
AK: Add String::trim
2023-01-28 00:13:46 +00:00
Timothy Flynn
cccaa94767
AK: Add String::join
2023-01-28 00:13:46 +00:00
Timothy Flynn
79aaa2fe0f
AK: Allow the kernel to have access to StringBuilder::to_string
...
This is mostly to prevent String.h from acquiring ifdef-soup. In any
case, it's fine for the kernel to see this symbol as it is fallible.
2023-01-28 00:13:46 +00:00
Linus Groh
6e7459322d
AK: Remove StringBuilder::build() in favor of to_deprecated_string()
...
Having an alias function that only wraps another one is silly, and
keeping the more obvious name should flush out more uses of deprecated
strings.
No behavior change.
2023-01-27 20:38:49 +00:00
Sam Atkins
09a22ddb2a
AK: Remove unimplemented methods
2023-01-27 20:33:18 +00:00
Sam Atkins
df07c5be3a
AK: Remove unused DateTimeLexer class
2023-01-27 20:33:18 +00:00
Timothy Flynn
c35b1371a3
AK: Add an overload of String::find_byte_offset for StringView
2023-01-27 18:00:17 +00:00
Timothy Flynn
76fd5f2756
AK: Add convenience substring wrappers to String to exclude a length
...
These overloads exist on other string classes and are used throughout
the code base.
2023-01-24 16:23:50 -05:00
Timothy Flynn
427b82065c
AK: Add a method to create a String with a repeated code point
2023-01-24 16:23:50 -05:00
Timothy Flynn
d50724956e
AK: Add a method to find the byte offset of a code point
2023-01-24 16:23:50 -05:00
Timothy Flynn
5e44b93af2
AK: Remove [[nodiscard]] attribute from String methods returning ErrorOr
2023-01-24 16:23:50 -05:00
Nico Weber
44de4d163b
AK: Make HashMap::try_ensure work with a fallible construction callback
...
Co-authored-by: Timothy Flynn <trflynn89@pm.me>
2023-01-24 14:45:27 +00:00
Nico Weber
8b5b767465
AK: Print leading zeroes after the dot for FixedPoint numbers
...
As a nearby comment says, "This is a terrible approximation".
This doesn't make things less terrible, but it does make things
more correct in the given framework of terribleness.
Fixes #17156 .
2023-01-24 13:24:21 +01:00
Nico Weber
9c5820326d
AK: Make FixedPoint::create_raw public and constexpr
2023-01-23 18:09:23 +00:00
Sam Atkins
c7a66882f4
AK: Make NonnullPtrVectors shuffleable
...
AK::shuffle() doesn't work on these, because their operator[] returns a
reference to the pointed-at value, instead of to the NonnullPtr itself.
2023-01-22 21:31:36 +00:00
Nico Weber
aa9037eed4
AK: Add spec comments to Utf16CodePointIterator::operator*()
2023-01-22 21:30:44 +00:00
Timothy Flynn
ef275e25b8
AK: Reduce String's allocated data by one byte
...
This was copied from allocation_size_for_stringimpl, which had to ensure
the string is null-terminated. String makes no such guarantee.
2023-01-22 20:27:52 +00:00
Karol Kosek
2d976ab2a6
AK: Define is_trivially_serializable trait for Little and BigEndian<>
...
This will allow us get LittleEndian<> and BigEndian<> wrapped types
directly from Stream::read_value<>().
2023-01-22 20:58:42 +01:00
Timothy Flynn
12c8bc3e85
AK: Add a String factory to create a string from a single code point
2023-01-22 01:03:13 +00:00
Timothy Flynn
8aca8e82cb
AK: Change String's default constructor to be constant
...
This allows creating expressions such as:
constexpr Array<String, 10> {};
2023-01-22 01:03:13 +00:00
Andrew Kaster
7ab37ee22c
Everywhere: Remove string.h include from AK/Traits.h and resolve fallout
...
A lot of places were relying on AK/Traits.h to give it strnlen, memcmp,
memcpy and other related declarations.
In the quest to remove inclusion of LibC headers from Kernel files, deal
with all the fallout of this included-everywhere header including less
things.
2023-01-21 10:43:59 -07:00
Tim Schumacher
63cf9b973d
AK: Remove FileStream
2023-01-21 14:43:56 +01:00
martinfalisse
aec2dadfdd
AK: Add split()
for String
2023-01-21 14:35:00 +01:00
Timothy Flynn
4f5353cbb8
AK: Rename double_hash to rehash_for_collision
...
The name is currently quite confusing as it indicates it hashes doubles.
2023-01-21 10:36:14 +01:00
Timothy Flynn
60b56892ca
AK: Add a type alias for DistinctNumeric's underlying type
2023-01-21 10:36:14 +01:00
Tim Schumacher
49b30d3013
AK: Remove InputBitStream
and OutputBitStream
2023-01-21 00:45:33 +00:00
Tim Schumacher
d7eead4f4c
AK: Remove DuplexMemoryStream
2023-01-20 20:48:40 +00:00