سؤال

I have a multidimensional points which may have keys of the following 3 types INT(4) i.e. Short , or INT(8) or varchar(512).

For this reason I can't use normal Hilbert curve transformation. I found a very good resource to calculate compact hilbert indices. Here is the link.

http://web.cs.dal.ca/~chamilto/hilbert/index.html

I understand the points and motivation in his paper but I am unable to decipher the code. I can't figure out which functions to call to calculate Compact Hilbert Indices and the inverse of it.

هل كانت مفيدة؟

المحلول

http://code.google.com/p/uzaygezen/ is an open source Java implementation of the Compact Hilbert Index. Here's an example corresponding to 3 dimensions with 4, 8 and 512 bytes, as specified in the question:

CompactHilbertCurve chc = new CompactHilbertCurve(new int[] {4 * 8, 8 * 8, 512 * 8});
List<Integer> bitsPerDimension = chc.getSpec().getBitsPerDimension();
BitVector[] p = new BitVector[bitsPerDimension.size()];
for (int i = p.length; --i >= 0; ) {
    p[i] = BitVectorFactories.OPTIMAL.apply(bitsPerDimension.get(i));
}
p[0].copyFrom(123);
p[1].copyFrom(32342);
p[2].copyFrom(BitSet.valueOf("test".getBytes("ISO-8859-1")));
BitVector chi = BitVectorFactories.OPTIMAL.apply(chc.getSpec().sumBitsPerDimension());
chc.index(p, 0, chi);
System.out.println(chi);

نصائح أخرى

If you download the code and look at the header file, it should be self explanatory (btw, the lib built fine for me on Ubuntu):

// Description of parameters:
//
// FOR REGULAR HILBERT INDICES
//
// CFixBitVec/CBigBitVec *p
// Pointer to array of non-negative coordinate values.
//
// int m
// Precision of all coordinate values (number of bits required to
// represent the largest possible coordinate value).
//
// int n
// Number of dimensions (size of the array *p).
//
// CFixBitVec/CBigBitVec &h
// Hilbert index of maximum precision m*n.
//
// int *ms
// Array of precision values, one per dimension.
//
// FOR COMPACT HILBERT INDICES
//
// CFixBitVec/CBigBitVec &hc
// Compact Hilbert index of maximum precision M.
//
// int M
// Net precision value, corresponding to the size of the compact
// Hilbert code.  If not provided, defaults to zero and will be calculated
// by the function (sum_i { ms[i] }).
//
// int m
// Largest precision value (max_i { ms[i] }).  If not provided, defaults
// to zero and will be calculated by the function,


namespace Hilbert
{
    // fix -> fix
    void coordsToIndex( const CFixBitVec *p, int m, int n, CFixBitVec &h );
    void indexToCoords( CFixBitVec *p, int m, int n, const CFixBitVec &h );
    void coordsToCompactIndex( const CFixBitVec *p, const int *ms, int n,
        CFixBitVec &hc, int M = 0, int m = 0 );
    void compactIndexToCoords( CFixBitVec *p, const int *ms, int n,
        const CFixBitVec &hc, int M = 0, int m = 0 );

    // fix -> big
    void coordsToIndex( const CFixBitVec *p, int m, int n, CBigBitVec &h );
    void indexToCoords( CFixBitVec *p, int m, int n, const CBigBitVec &h );
    void coordsToCompactIndex( const CFixBitVec *p, const int *ms, int n,
        CBigBitVec &hc, int M = 0, int m = 0 );
    void compactIndexToCoords( CFixBitVec *p, const int *ms, int n,
        const CBigBitVec &hc, int M = 0, int m = 0 );

    // big -> big
    void coordsToIndex( const CBigBitVec *p, int m, int n, CBigBitVec &h );
    void indexToCoords( CBigBitVec *p, int m, int n, const CBigBitVec &h );
    void coordsToCompactIndex( const CBigBitVec *p, const int *ms, int n,
        CBigBitVec &hc, int M = 0, int m = 0 );
    void compactIndexToCoords( CBigBitVec *p, const int *ms, int n,
        const CBigBitVec &hc, int M = 0, int m = 0 );
};
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top