Legofit
infers population history from nucleotide site patterns.
binary.h
1#ifndef ARR_BINARY_H
2# define ARR_BINARY_H
3
4# include "typedefs.h"
5# include <stddef.h>
6# include <stdint.h>
7# include <stdio.h>
8
9void printBits(size_t size, void const *const ptr, FILE *fp);
10void printWhichBits(size_t size, void const *const ptr);
11int getBits(tipId_t x, int maxbits, int *bit);
12int num1bits(tipId_t x);
13static inline tipId_t reverseBits(tipId_t x);
14uint32_t rev32(uint32_t x);
15uint64_t rev64(uint64_t x);
16#ifdef __GNUC__
17uint32_t uint32Hash(uint32_t key );
18uint32_t uint64Hash(uint64_t key);
19#else
20uint32_t uint32Hash(uint32_t key ) __attribute__((no_sanitize("integer")));
21uint32_t uint64Hash(uint64_t key) __attribute__((no_sanitize("integer")));
22#endif
23int nlz(tipId_t x);
24int nlz64(uint64_t x);
25int no_shared_bits(int n, tipId_t *tid);
26static inline int isPow2(tipId_t x);
27tipId_t next_power_of_2(tipId_t x);
28tipId_t low_bits_on(unsigned n);
29
30static inline int isPow2(tipId_t x) {
31 return (x > 0 && !(x & (x - 1)));
32}
33
35static inline tipId_t reverseBits(tipId_t x) {
36#if TIPID_SIZE==32
37 return rev32(x);
38#elif TIPID_SIZE==64
39 return rev64(x);
40#else
41# error "unsupported tipId_t size"
42#endif
43}
44
45#endif
uint32_t rev32(uint32_t x)
Reverse bits in a 32-bit integer.
Definition: binary.c:19
uint64_t rev64(uint64_t x)
Reverse bits in a 64-bit integer.
Definition: binary.c:30
int getBits(tipId_t x, int maxbits, int bit[maxbits])
Examine the bits in x.
Definition: binary.c:122
void printWhichBits(size_t const size, void const *const ptr)
Print the (0-based) indices of the bits that are "on".
Definition: binary.c:144
void printBits(size_t size, void const *const ptr, FILE *fp)
Print the bits in an object of size "size", pointed to by "ptr".
Definition: binary.c:97
int no_shared_bits(int n, tipId_t *tid)
Return 1 if the values in array share no bits; 0 otherwise.
Definition: binary.c:232
int nlz64(uint64_t x)
Number of leading zeroes in 64-bit unsigned integer.
Definition: binary.c:62
uint32_t uint64Hash(uint64_t key)
Hash function for a 64-bit integer.
Definition: binary.c:218
tipId_t next_power_of_2(tipId_t x)
Round up to the next largest power of 2.
Definition: binary.c:180
int nlz(tipId_t x)
Number of leading zeroes in tipId_t variable.
Definition: binary.c:85
int num1bits(tipId_t x)
Count the number of 1 bits in x.
Definition: binary.c:169
uint32_t uint32Hash(uint32_t key)
Hash function for a 32-bit integer.
Definition: binary.c:202