aboutsummaryrefslogtreecommitdiff
path: root/src/integers.nim
diff options
context:
space:
mode:
authorpacien2018-11-23 12:57:00 +0100
committerpacien2018-11-23 13:00:53 +0100
commitd9768cd0315b0415d20818de9c897c6168c95b78 (patch)
tree41987740d02f689550436384dd7d2b755aa85869 /src/integers.nim
parentc87ea5c5d11bffbe84acf66215e6bf5a5e047a50 (diff)
downloadgziplike-d9768cd0315b0415d20818de9c897c6168c95b78.tar.gz
Split bitstream into bitreader and bitwriter
Diffstat (limited to 'src/integers.nim')
-rw-r--r--src/integers.nim7
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
23proc truncateToUint8*(x: SomeUnsignedInt): uint8 = 23proc truncateToUint8*(x: SomeUnsignedInt): uint8 =
24 (x and wordBitMask).uint8 24 (x and wordBitMask).uint8
25
26iterator 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)