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/GetLocation.hpp | 96 ++++++------------------------------------------- 1 file changed, 10 insertions(+), 86 deletions(-) (limited to 'Hilbert/GetLocation.hpp') diff --git a/Hilbert/GetLocation.hpp b/Hilbert/GetLocation.hpp index e66dc04..7fc2bca 100644 --- a/Hilbert/GetLocation.hpp +++ b/Hilbert/GetLocation.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,95 +19,19 @@ #ifndef _GETLOCATION_HPP_ #define _GETLOCATION_HPP_ +#include -#include +namespace Hilbert { - -namespace Hilbert +template +inline void +getLocation(const P* const p, const int n, const int i, I& l) { - - template - inline - void - _getLocation( - const P *p, - int jo, - int jn, - int ir, - FBV_UINT im, - FBV_UINT &l - ) - { - l = 0; - switch ( jn ) - { -#define GETLOC_CASE(i) case ((i)+1): if (p[jo+(i)].racks()[ir]&im) l|=(FBV1<<(i)) -#define GETLOC_CASE2(i) \ - GETLOC_CASE(i+1); \ - GETLOC_CASE(i) -#define GETLOC_CASE4(i) \ - GETLOC_CASE2(i+2); \ - GETLOC_CASE2(i) -#define GETLOC_CASE8(i) \ - GETLOC_CASE4(i+4); \ - GETLOC_CASE4(i) -#define GETLOC_CASE16(i) \ - GETLOC_CASE8(i+8); \ - GETLOC_CASE8(i) -#define GETLOC_CASE32(i) \ - GETLOC_CASE16(i+16); \ - GETLOC_CASE16(i) -#if FBV_BITS == 64 - GETLOC_CASE32(32); -#endif - GETLOC_CASE32(0); - } - return; - } - - - template - inline - void - getLocation( - const P *p, - int n, - int i, - I &l - ) - { - /*int j; - for ( j = n-1; j >= 0; --j ) - l.set(j,p[j].test(i)); - return;*/ - - int j, jo, ir; - FBV_UINT im; - - if ( P::type() == eBig ) - { - ir = i / FBV_BITS; - im = FBV1 << (i-ir*FBV_BITS); - } - else - { - ir = 0; - im = FBV1 << i; - } - - j = 0; - jo = 0; - if ( I::type() == eBig ) - { - for ( ; j < l.rackCount()-1; ++j, jo += FBV_BITS ) - _getLocation(p,jo,FBV_BITS,ir,im,l.racks()[j]); - } - _getLocation(p,jo,n-jo,ir,im,l.racks()[j]); - - return; + for (int j = 0; j < n; ++j) { + setBit(l, j, testBit(p[j], i)); } - -}; +} +} // namespace Hilbert #endif -- cgit v1.2.1