|
This library has been deprecated in favor of KPD |
Simple library that provides Deque implementations for all Kotlin’s primitive types that deal in unboxed values.
build.gradle.kts
dependencies {
implementation("io.foxcapades.lib:pdk:1.2.0")
}
val deque = ByteDeque(8192)
val read = deque.fillFrom(inputStream)
for (i in 0 until read step 8)
println(deque.popLong())
ℹ️
|
This is just an example, the JDK’s builtin type ByteBuffer is able to
read long values from a stream up to 50% faster than ByteDeque due to
ByteBuffer utilizing the Unsafe class to raw cast bytes in memory as a long
value.
|
Similar to the JDK’s Queue
type and various implementations, the *Deque
types have multiple aliases for most properties and methods that align with
different use cases or implementations from different languages. Each alias is
an inline method or property allowing library users to choose the specific
syntax they prefer without any call-stack overhead. This is particularly useful
when porting libraries or code from other languages such as C++ into Kotlin.
The head and tail of the deque are named just that, "head", and "tail", however
they are also accessible via "front", "first", "back", and "last" for most
properties and methods, for example, the property head
, which is handle on the
first element in the deque, has the alias properties first
and front
,
similarly the method pushHead
, which pushes an element onto the head of the
deque, has the alias methods pushFirst
and pushFront
.
pdk
aims to be as lightweight as possible both in terms of memory and compute
footprint. All of the PrimitiveDeque
implementations wrap 3 properties, a
primitive array of a specified capacity, an int
value recording the current
size of the deque, and one more int
value tracking the internal 'head'
position in the deque’s backing array.
Additionally, in all situations where it is possible, copy operations are
performed by the native arrayCopy
method.
Presently the only situation where arrayCopy
is not used on copy is when
copying the contents of a Collection
instance into a deque.
Comparison of basic deque functions across libraries.
Action | C++std::deque |
JDKDeque |
JSdenque |
PDK*Deque |
---|---|---|---|---|
Peek first element |
|
|
|
|
Peek last element |
|
|
|
|
Pop & return first element |
|
|
|
|
Pop & return last element |
|
|
|
|
Push element to front |
|
|
|
|
Push element to back |
|
|
|
|
Delete first element |
|
|
||
Delete last element |
|
|
||
Empty test |
|
|
|
|
Clear deque |
|
|
|
|
Indexed access |
|
|
|
The following additional functions and operators are available on all deque
implementations included in the pdk
library.
Method / Operator | Description |
---|---|
|
Clones the deque and it’s data. |
|
Tests whether the deque contains an element equal to the given value. |
|
Copies data from the deque into the given array starting at the given offset. |
|
Returns an iterator over the contents of the deque. |
|
Calls the given function on every element of the deque. |
|
Appends the elements of the given value to the back of the deque. |
|
|
|
|
|
Creates a new deque containing the elements from both original deques. |
|
Returns a new deque containing the contents of the target deque in the given index range. |
|
|
|
Returns an array containing the contents of the target deque in the given index range. |
|
Method / Operator | Description |
---|---|
|
Fills the remaining space in the |
|
Pops the first 2 bytes from the deque and parses them as a |
|
Pops the first 4 bytes from the deque and parses them as an |
|
Pops the first 8 bytes from the deque and parses them as a |
|
Pops the first 4 bytes from the deque and parses them as a |
|
Pops the first 8 bytes from the deque and parses them as a |
|
Pops the first byte from the deque as a |
|
Pops the first 2 bytes from the deque and parses them as a |
|
Pops the first 4 bytes from the deque and parses them as a |
|
Pops the first 8 bytes from the deque and parses them as a |
Method / Operator | Description |
---|---|
|
Appends the characters of the given value to the back of the deque. |
|
|
|
Creates a new |
Method / Operator | Description |
---|---|
|
Fills the remaining space in the |
|
Pops the first value from the deque as a |
|
Pops the first 2 unsigned bytes from the deque and parses them as a |
|
Pops the first 4 unsigned bytes from the deque and parses them as an |
|
Pops the first 8 unsigned bytes from the deque and parses them as a |
|
Pops the first 4 unsigned bytes from the deque and parses them as a |
|
Pops the first 8 unsigned bytes from the deque and parses them as a |
|
Pops the first 2 unsigned bytes from the deque and parses them as a |
|
Pops the first 4 unsigned bytes from the deque and parses them as a |
|
Pops the first 8 unsigned bytes from the deque and parses them as a |