diff options
author | David Robillard <d@drobilla.net> | 2018-08-04 23:13:50 +0200 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2018-08-07 20:01:14 +0200 |
commit | c5ad5673a76ba969edadfb3d5cfd5a2516b6fdcd (patch) | |
tree | f2b8b625910601479ac48d3315d36e5299ad6d8a /Hilbert/SetBits.hpp | |
parent | acb6aae319ba56bc52bf6209c343a3f46c624ad8 (diff) | |
download | chilbert-c5ad5673a76ba969edadfb3d5cfd5a2516b6fdcd.tar.gz chilbert-c5ad5673a76ba969edadfb3d5cfd5a2516b6fdcd.tar.bz2 chilbert-c5ad5673a76ba969edadfb3d5cfd5a2516b6fdcd.zip |
Simplify bit operations and support integral points
Diffstat (limited to 'Hilbert/SetBits.hpp')
-rw-r--r-- | Hilbert/SetBits.hpp | 77 |
1 files changed, 12 insertions, 65 deletions
diff --git a/Hilbert/SetBits.hpp b/Hilbert/SetBits.hpp index 5f311f1..a040b8a 100644 --- a/Hilbert/SetBits.hpp +++ b/Hilbert/SetBits.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 _SETBITS_HPP_ #define _SETBITS_HPP_ +#include <Hilbert/Operations.hpp> -#include <Hilbert/BigBitVec.hpp> +namespace Hilbert { - -namespace Hilbert +template <class H, class I> +inline void setBits(H& h, // destination + const int n, // number of bits + const int i, // bit position + const I& w) // bits to place { - - template<class H,class I> - inline - void - setBits( - H &h, // destination - int n, // number of bits - int i, // bit position - const I &w // bits to place - ) - { - // This is terribly inefficient. - int j; - for ( j = 0; j < n; j++ ) - h.set(i+j,w.test(j)); + for (int j = 0; j < n; j++) { + setBit(h, i + j, testBit(w, j)); } +} - - // <CBigBitVec,CBigBitVec> - // #TODO - - - // <CBigBitVec,CFixBitVec> - template<> - inline - void - setBits( - CBigBitVec &h, - int n, - int i, - const CFixBitVec &w - ) - { - int ir, ib, t; - BBV_MODSPLIT(ir,ib,i); - h.racks()[ir] |= w.rack() << ib; - t = ib+n; - if ( t > FBV_BITS ) - { - t -= FBV_BITS; - h.racks()[ir+1] |= w.rack() >> t; - } - return; - } - - - // <CFixBitVec,CFixBitVec> - template<> - inline - void - setBits( - CFixBitVec &h, - int n, - int i, - const CFixBitVec &w - ) - { - h |= w << i; - return; - } - -}; - +} // namespace Hilbert #endif |