bit fields

This commit is contained in:
alexander.nutz
2024-03-25 11:25:05 +01:00
parent c4e90f4246
commit 59a288c849
4 changed files with 64 additions and 2 deletions

29
README.md Normal file
View File

@@ -0,0 +1,29 @@
# Blitz
Kotlin library which mainly focuses on functional programming.
Features:
- Monads
- Either
- Caching delegated property (similar to lazy)
- A lot of sequence utils
- Streaming IO using kotlinx.io
- ByteVec (alternative to ByteBuf)
- BitVec (similar to bit sets in other languages)
- "Lazy" sequences
- A lot of generative sequence types
- BitField
## How to get
```kotlin
repositories {
maven {
name = "alex's repo"
url = uri("http://207.180.202.42:8080/libs")
isAllowInsecureProtocol = true
}
}
dependencies {
implementation("me.alex_s168:blitz:0.1")
}
```

View File

@@ -5,7 +5,7 @@ plugins {
}
group = "me.alex_s168"
version = "0.1"
version = "0.2"
repositories {
mavenCentral()

View File

@@ -2,5 +2,5 @@ plugins {
id("org.gradle.toolchains.foojay-resolver-convention") version "0.5.0"
}
rootProject.name = "kotlin-bits"
rootProject.name = "blitz"

View File

@@ -0,0 +1,33 @@
package blitz
import blitz.collections.BitVec
import kotlin.reflect.KProperty
abstract class BitField {
private var vec = BitVec(1)
protected class BitDelegate(
private val thi: BitField,
private val pos: Int,
) {
operator fun getValue(thisRef: Any?, property: KProperty<*>): Boolean =
thi.vec[pos]
operator fun setValue(thisRef: Any?, property: KProperty<*>, value: Boolean) {
thi.vec[pos] = value
}
}
protected fun bit(pos: Int): BitDelegate =
BitDelegate(this, pos)
fun decode(byte: Byte) {
vec = BitVec.from(byteArrayOf(byte))
}
fun encode(): Byte =
vec.toBytes()[0]
override fun toString(): String =
"${this::class.simpleName}(0b${vec.toBytes()[0].toString(2)})"
}