diff options
author | pacien | 2018-11-23 12:57:00 +0100 |
---|---|---|
committer | pacien | 2018-11-23 13:00:53 +0100 |
commit | d9768cd0315b0415d20818de9c897c6168c95b78 (patch) | |
tree | 41987740d02f689550436384dd7d2b755aa85869 /src/integers.nim | |
parent | c87ea5c5d11bffbe84acf66215e6bf5a5e047a50 (diff) | |
download | gziplike-d9768cd0315b0415d20818de9c897c6168c95b78.tar.gz |
Split bitstream into bitreader and bitwriter
Diffstat (limited to 'src/integers.nim')
-rw-r--r-- | src/integers.nim | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/src/integers.nim b/src/integers.nim index 1b9121c..1f83488 100644 --- a/src/integers.nim +++ b/src/integers.nim | |||
@@ -22,3 +22,10 @@ proc `/^`*[T: Natural](x, y: T): T = | |||
22 | 22 | ||
23 | proc truncateToUint8*(x: SomeUnsignedInt): uint8 = | 23 | proc truncateToUint8*(x: SomeUnsignedInt): uint8 = |
24 | (x and wordBitMask).uint8 | 24 | (x and wordBitMask).uint8 |
25 | |||
26 | iterator chunks*(totalBitLength: int, chunkType: typedesc[SomeInteger]): tuple[index: int, chunkBitLength: int] = | ||
27 | let chunkBitLength = sizeof(chunkType) * wordBitLength | ||
28 | let wordCount = totalBitLength div chunkBitLength | ||
29 | for i in 0..<(wordCount): yield (i, chunkBitLength) | ||
30 | let remainder = totalBitLength mod chunkBitLength | ||
31 | if remainder > 0: yield (wordCount, remainder) | ||