From d9768cd0315b0415d20818de9c897c6168c95b78 Mon Sep 17 00:00:00 2001 From: pacien Date: Fri, 23 Nov 2018 12:57:00 +0100 Subject: Split bitstream into bitreader and bitwriter --- src/integers.nim | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src/integers.nim') 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 = proc truncateToUint8*(x: SomeUnsignedInt): uint8 = (x and wordBitMask).uint8 + +iterator chunks*(totalBitLength: int, chunkType: typedesc[SomeInteger]): tuple[index: int, chunkBitLength: int] = + let chunkBitLength = sizeof(chunkType) * wordBitLength + let wordCount = totalBitLength div chunkBitLength + for i in 0..<(wordCount): yield (i, chunkBitLength) + let remainder = totalBitLength mod chunkBitLength + if remainder > 0: yield (wordCount, remainder) -- cgit v1.2.3