diff options
author | David Robillard <d@drobilla.net> | 2018-08-04 19:12:43 +0200 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2018-08-04 20:04:30 +0200 |
commit | 3ea9ed0d2a14468d698dfe24bdb790b6f4103596 (patch) | |
tree | 4452a4920f46bba6fdc67bc2bb56332e456e6be4 /Hilbert/SetLocation.hpp | |
download | chilbert-3ea9ed0d2a14468d698dfe24bdb790b6f4103596.tar.gz chilbert-3ea9ed0d2a14468d698dfe24bdb790b6f4103596.tar.bz2 chilbert-3ea9ed0d2a14468d698dfe24bdb790b6f4103596.zip |
Initial import
Diffstat (limited to 'Hilbert/SetLocation.hpp')
-rw-r--r-- | Hilbert/SetLocation.hpp | 96 |
1 files changed, 96 insertions, 0 deletions
diff --git a/Hilbert/SetLocation.hpp b/Hilbert/SetLocation.hpp new file mode 100644 index 0000000..d7b5099 --- /dev/null +++ b/Hilbert/SetLocation.hpp @@ -0,0 +1,96 @@ +/* + * Copyright (C) 2006-2007 Chris Hamilton <chamilton@cs.dal.ca> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef _SETLOCATION_HPP_ +#define _SETLOCATION_HPP_ + + +#include <Hilbert/Common.hpp> +#include <Hilbert/BigBitVec.hpp> + + +namespace Hilbert +{ + template <class P,class I> + H_INLINE + void + setLocation( + P *p, + int n, + int i, + const I &l + ) + { + // Easy to understand implementation + /*int j; + for ( j = 0; j < n; j++ ) + p[j].setBit(i,l.getBit(j)); + return;*/ + + // Much faster loop-unrolled implementation. + int ir, ib; + FBV_UINT im; + BBV_MODSPLIT(ir,ib,i); + im = (FBV1<<ib); + +#define SETBIT p->racks()[ir]|=im; if ((*lr&jm)==0) p->racks()[ir]^=im; jm<<=1; ++p; +#define SETBIT1(a) \ + case (a+1): SETBIT; +#define SETBIT2(a) \ + SETBIT1(a+1); \ + SETBIT1(a); +#define SETBIT4(a) \ + SETBIT2(a+2); \ + SETBIT2(a); +#define SETBIT8(a) \ + SETBIT4(a+4); \ + SETBIT4(a); +#define SETBIT16(a) \ + SETBIT8(a+8); \ + SETBIT8(a); +#define SETBIT32(a) \ + SETBIT16(a+16); \ + SETBIT16(a); + + int j = 0; + FBV_UINT jm = 1; + const FBV_UINT *lr = l.racks(); + while ( j < n ) + { + if ( jm == 0 ) + { + jm = 1; + ++lr; + } + + int dj = n - j; + switch ( n - j ) + { + default: dj = 32; + SETBIT32(0); + } + j += dj; + } + + return; + } + +}; + + +#endif |