aboutsummaryrefslogtreecommitdiff
path: root/src/integers.nim
diff options
context:
space:
mode:
authorpacien2018-11-28 15:20:14 +0100
committerpacien2018-11-28 15:20:14 +0100
commitd661132528d5c27148a0b55d52709ce97124000a (patch)
tree31aeb46872fd70b409633e163c0bc0bfbb825429 /src/integers.nim
parent3d44208aaaeca516eb08a90c98635543cae2bd4d (diff)
downloadgziplike-d661132528d5c27148a0b55d52709ce97124000a.tar.gz
add huffman tree structure and serialisation
Diffstat (limited to 'src/integers.nim')
-rw-r--r--src/integers.nim6
1 files changed, 6 insertions, 0 deletions
diff --git a/src/integers.nim b/src/integers.nim
index 7b0f166..c93c9b8 100644
--- a/src/integers.nim
+++ b/src/integers.nim
@@ -22,6 +22,12 @@ proc `/^`*[T: Natural](x, y: T): T =
22proc truncateToUint8*(x: SomeUnsignedInt): uint8 = 22proc truncateToUint8*(x: SomeUnsignedInt): uint8 =
23 (x and uint8.high).uint8 23 (x and uint8.high).uint8
24 24
25proc bitLength*[T: SomeUnsignedInt](x: T): int =
26 var buf = x
27 while buf > 0.T:
28 buf = buf shr 1
29 result += 1
30
25proc leastSignificantBits*[T: SomeUnsignedInt](x: T, bits: int): T = 31proc leastSignificantBits*[T: SomeUnsignedInt](x: T, bits: int): T =
26 let maskOffset = sizeof(T) * wordBitLength - bits 32 let maskOffset = sizeof(T) * wordBitLength - bits
27 if maskOffset >= 0: (x shl maskOffset) shr maskOffset else: x 33 if maskOffset >= 0: (x shl maskOffset) shr maskOffset else: x