/usr/include/kmer/util/unaryEncoding.h is in libkmer-dev 0~20150903+r2013-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 | #ifndef UNARY_ENCODING_H
#define UNARY_ENCODING_H
#include "bitPacking.h"
// Routines to store and retrieve a unary encoded number to/from a
// bit packed word array based at 'ptr' and currently at location
// 'pos'. Both routines return the size of the encoded number in
// 'siz'.
// The usual unary encoding. Store the number n as n 0 bits followed
// by a single 1 bit.
//
// 0 -> 1
// 1 -> 01
// 2 -> 001
// 3 -> 0001
// 4 -> 00001
//
// See the decoder as to why we use 0 instead of 1 for the count.
inline
void
setUnaryEncodedNumber(uint64 *ptr,
uint64 pos,
uint64 *siz,
uint64 val) {
*siz = val + 1;
while (val >= 64) {
setDecodedValue(ptr, pos, 64, uint64ZERO);
pos += 64;
val -= 64;
siz += 64;
}
setDecodedValue(ptr, pos, val + 1, uint64ONE);
pos += val + 1;
}
inline
uint64
getUnaryEncodedNumber(uint64 *ptr,
uint64 pos,
uint64 *siz) {
uint64 val = uint64ZERO;
uint64 enc = uint64ZERO;
// How many whole words are zero?
//
enc = getDecodedValue(ptr, pos, 64);
while (enc == uint64ZERO) {
val += 64;
pos += 64;
enc = getDecodedValue(ptr, pos, 64);
}
// This word isn't zero. Count how many bits are zero (see, the
// choice of 0 or 1 for the encoding wasn't arbitrary!)
//
val += 64 - logBaseTwo64(enc);
*siz = val + 1;
return(val);
}
#endif // UNARY_ENCODING_H
|