diff options
Diffstat (limited to 'Hilbert/GetBits.hpp')
-rw-r--r-- | Hilbert/GetBits.hpp | 77 |
1 files changed, 12 insertions, 65 deletions
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 <d@drobilla.net> * Copyright (C) 2006-2007 Chris Hamilton <chamilton@cs.dal.ca> * * This program is free software; you can redistribute it and/or modify @@ -19,74 +19,21 @@ #ifndef _GETBITS_HPP_ #define _GETBITS_HPP_ +#include <Hilbert/Operations.hpp> -#include <Hilbert/BigBitVec.hpp> +namespace Hilbert { - -namespace Hilbert +template <class H, class I> +inline void getBits(const H& h, // bits to read + const int n, // number of bits + const int i, // bit index + I& w) // destination { - template <class H,class I> - 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; - } - - - // <CBigBitVec,CBigBitVec> - // #TODO - - // <CBigBitVec,CFixBitVec> - 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; - } - - - // <CFixBitVec,CFixBitVec> - 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 |