aboutsummaryrefslogtreecommitdiffstats
path: root/Hilbert/GetBits.hpp
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2018-08-04 23:13:50 +0200
committerDavid Robillard <d@drobilla.net>2018-08-07 20:01:14 +0200
commitc5ad5673a76ba969edadfb3d5cfd5a2516b6fdcd (patch)
treef2b8b625910601479ac48d3315d36e5299ad6d8a /Hilbert/GetBits.hpp
parentacb6aae319ba56bc52bf6209c343a3f46c624ad8 (diff)
downloadchilbert-c5ad5673a76ba969edadfb3d5cfd5a2516b6fdcd.tar.gz
chilbert-c5ad5673a76ba969edadfb3d5cfd5a2516b6fdcd.tar.bz2
chilbert-c5ad5673a76ba969edadfb3d5cfd5a2516b6fdcd.zip
Simplify bit operations and support integral points
Diffstat (limited to 'Hilbert/GetBits.hpp')
-rw-r--r--Hilbert/GetBits.hpp77
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