From c5ad5673a76ba969edadfb3d5cfd5a2516b6fdcd Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sat, 4 Aug 2018 23:13:50 +0200 Subject: Simplify bit operations and support integral points --- Hilbert/GetBits.hpp | 77 +++++++++-------------------------------------------- 1 file changed, 12 insertions(+), 65 deletions(-) (limited to 'Hilbert/GetBits.hpp') diff --git a/Hilbert/GetBits.hpp b/Hilbert/GetBits.hpp index 461690c..9f7feb6 100644 --- a/Hilbert/GetBits.hpp +++ b/Hilbert/GetBits.hpp @@ -1,4 +1,4 @@ -/* +/* Copyright (C) 2018 David Robillard * Copyright (C) 2006-2007 Chris Hamilton * * This program is free software; you can redistribute it and/or modify @@ -19,74 +19,21 @@ #ifndef _GETBITS_HPP_ #define _GETBITS_HPP_ +#include -#include +namespace Hilbert { - -namespace Hilbert +template +inline void getBits(const H& h, // bits to read + const int n, // number of bits + const int i, // bit index + I& w) // destination { - template - inline - void - getBits( - const H &h, // bits to read - int n, // number of bits - int i, // bit index - I &w // destination - ) - { - // This is terribly inefficient. - int j; - for ( j = 0; j < n; j++ ) - w.set(j,h.test(i+j)); - return; - } - - - // - // #TODO - - // - template<> - inline - void - getBits( - const CBigBitVec &h, - int n, - int i, - CFixBitVec &w - ) - { - int ir, ib, t; - BBV_MODSPLIT(ir,ib,i); - w.rack() = h.racks()[ir] >> ib; - t = FBV_BITS - ib; - if ( t < n ) - { - w.rack() |= h.racks()[ir+1] >> (FBV_BITS-n); - } - w.truncate(n); - return; - } - - - // - template<> - inline - void - getBits( - const CFixBitVec &h, - int n, - int i, - CFixBitVec &w - ) - { - w = h >> i; - w.truncate(n); - return; + for (int j = 0; j < n; j++) { + setBit(w, j, testBit(h, i + j)); } +} -}; - +} // namespace Hilbert #endif -- cgit v1.2.1