    Encoding and Decoding Algorithms for Arbitrary Dimensional Hilbert Order

Hilbert order is widely applied in many areas. However, most of the algorithms are confined to low dimensional cases. In this paper, algorithms for encoding and decoding arbitrary dimensional Hilbert order are presented. Eight algorithms are proposed. Four algorithms are based on arithmetic operations and the other four algorithms are based on bit operations. For the algorithms complexities, four of them are linear and the other four are constant for given inputs. In the end of the paper, algorithms for two dimensional Hilbert order are presented to demonstrate the usage of the algorithms introduced.

Authors

11/03/2020

Function values are enough for L_2-approximation: Part II

In the first part we have shown that, for L_2-approximation of functions...
05/11/2021

Two novel feature selection algorithms based on crowding distance

In this paper, two novel algorithms for features selection are proposed....
04/26/2018

On the Arithmetic Complexities of Hamming Codes and Hadamard Codes

In this paper, we study the arithmetic complexities of Hamming codes and...
02/03/2010

K-Dimensional Coding Schemes in Hilbert Spaces

This paper presents a general coding method where data in a Hilbert spac...
07/14/2011

A Hilbert Scheme in Computer Vision

Multiview geometry is the study of two-dimensional images of three-dimen...
11/16/2020

Several self-adaptive inertial projection algorithms for solving split variational inclusion problems

This paper is to analyze the approximation solution of a split variation...
This week in AI

Get the week's most popular data science and artificial intelligence research sent straight to your inbox every Saturday.

1 Introduction

Space-filling curves were proposed by Peano in 1890 and popularized by Hilbert later. These curves introduce maps between one dimensional domain and multiple dimensional domain, which also introduce order when considering in one dimensional space. Hilbert space-filling curve is one famous space-filling curve, which is also called Hilbert curve. This kind of curve has many important characteristics, such as locality, clustering and self-similarity. Hilbert curve (order) has been applied in many areas, including image storing, database indexing, data compression and dynamic load balancing. For parallel computing, Hilbert order method is one of the most important geometry-based partitioning methods, which was implemented by the Zoltan , one of the most well-known dynamic load balancing package developed by Sandia National Laboratories. It was also implemented by PHG (Parallel Hierarchical Grid) , and it serves as the default dynamic load balancing strategy. The Hilbert order now are widely applied by many parallel applications [9, 14]. Details of space-filling curves can be found in .

A -dimensional Hilbert curve introduces a one-to-one mapping between -dimensional space and one-dimensional space. The mapping from -dimensional space to one-dimensional space is called encoding, while the inverse mapping is called decoding, which maps an integer to a coordinate in

-dimensional space. Algorithms for computing Hilbert curve/order in two and three dimensional spaces have been proposed in many literatures, which can be classified into recursive algorithms

[4, 5, 6, 7] and iterative algorithms [8, 9, 10, 11, 12, 13]. Iterative algorithms, especially the table-driven algorithms [8, 9], are usually much faster than recursive algorithms. In general, the complexities of these algorithms are , where is the level of the Hilbert curve. For two dimensional space, Chen et al  proposed an algorithm of complexity, where is defined as , and is independent of the level . The algorithm is faster when is much larger than . The same idea was also applied to three dimensional space . For higher dimensional spaces, relative little work has been done due to the complexity of Hilbert curve. Recently, Kamata et al presented a representative -dimensional Hilbert mapping algorithm  and Li et al introduced algorithms for analyzing the properties of -dimensional Hilbert curve .

In this paper, we present our work on developing algorithms for encoding and decoding arbitrary high dimensional Hilbert order bases on , and the authors introduced novel algorithms for analyzing evolutive rules for high dimensional Hilbert curve. However, the decoding and encoding algorithms for high dimensional spaces are still open problems. Here the rules are studied firstly and some properties are deduced. Then the encoding and decoding algorithms are proposed based on the properties deduced. For the encoding problems, four algorithms are presented. Two algorithms are based on arithmetic operations, which can be translated to bit operations naturally. Then two bit operation based algorithms are obtained. The decoding processes are reverse processes of encoding, thus decoding algorithms are obtained similarly. Four of our eight algorithms have linear complexity, O(m), where is the level of Hilbert order. The other four algorithms have constant complexity for given inputs. In the end of the paper, the algorithms are demonstrated in two dimensional space, and the results are discussed.

The layout of the paper is as follows. In §2, background and some notations are introduced firstly and then algorithms proposed in  are analyzed in detail. In §3, encoding and decoding algorithms are proposed. In §4, a two dimensional case is employed to illustrate our algorithms, and numerical experiments are performed to show the difference between linear complexity algorithm and constant complexity algorithm.

2 Preliminary

Notations are introduced and then the algorithms proposed in  are studied in detail. We should mention that all operations in this paper are performed on non-negative integers.

2.1 Notations

Let be the dimension of Hilbert curve and be the level of Hilbert curve. Let be the coordinate set of the -th level Hilbert curve, which is defined as . is a coordinate of the Hilbert curve, and is called the -th component of the coordinate. Logical operation for two coordinates is defined as

 (xn,⋯,x2,x1)∧(yn,⋯,y2,y1)=(xn∧yn,⋯,x2∧y2,x1∧y1), (1)

where is the regular exclusive or operation (xor).

Let represent a number system, where , and can be any positive integer. The number is binary number for , and decimal number for . For any non-negative integer , where , is defined as

 Rek(j)=Rek((a1a2⋯ak)2)=(b1b2⋯bk)2,bi=1−ai,1≤i≤k. (2)

The and, right and left shift operators are also introduced for the case that equals to two, denoted by , and , respectively. Let us define,

 pin(a1,a2,⋯,an)=(i∑j=1ai) mod 2=(i∑j=1ai) % 2, (3)

where equals to 0 or 1. The equals to 1 or 0. With the help of , the function is defined as

 fn(a1,a2,⋯,an)=(b1b2⋯bn)2=j,b1=a1,bi={ai, if pi−1n=01−ai, if pi−1n=1, (4)

where equals to 0 or 1 and is a decimal number. The function

maps a vector

to a decimal number . Its inverse function is defined as

 bn(j)=bn((a1a2⋯an)2)=(b1,b2,⋯,bn),b1=a1,bi={ai, if ai−1=01−ai, if ai−1=1, (5)

where is a decimal number and . The function maps a decimal number (scalar) to a vector.

Remarks. In practice, for a fixed value , and can be calculated aforehand and saved in tables, and this technique would speed up programs. can also be calculated in the following way

 bn((a1⋯an)2)=(a1,⋯,an)∧(0,a1,⋯,an−1). (6)

For the sake of completeness, concepts introduced in  are borrowed here. An -dimensional Hilbert cell is a -th level -dimensional Hilbert curve. The -dimensional Hilbert gene is a list of coordinate transformation commands, which direct the generation of the -th level Hilbert curve from

-th level Hilbert curve. The coordinate transformation commands include two types: exchange command and reverse command. These commands can be interpreted as reflection from some hyperplane, which will be presented in the next section. The Hilbert curve has direction, which has an entry and an exit. When the transformation commands are performed, the coordinates of entry and exit may be changed. In

, and , where , were introduced to represent the entry and exit for quadrant . Algorithms were also proposed to generate entry, exit and Hilbert gene list. Details can be found in .

2.2 Study of Evolutive Rules

Now we analyze the properties of algorithms developed in . Hilbert cell was generated in recursively in , in which if we wanted to generate dimensional Hilbert cell, the dimensional Hilbert cell should be generated aforehand. By using the function instead, the dimensional Hilbert cell can be generated directly.

The Hilbert gene list  includes two types of commands: exchange command and reverse command. Using mathematical techniques developed in this paper, each command can be interpreted as reflection from some hyperplane. For exchange command, if the command is performed between and , the hyperplane is , which means, for a point , , the coordinate of the new point is . This command just swaps and . For reverse command, if the command is performed on the -th position, and if the current level of Hilbert curve is , the hyperplane is , which means for any point , , the coordinate of the new point is . Here equals to . The reverse command changes only.

The algorithms which generateed gene list  can be rewritten as

 Gi,0n=(bn(0)∧bn(2n−1))∧(Hi,0n∧Hi,1n),(0≤i<2n) (7)
 Gi,1n=bn(0)∧Hi,0n,(0≤i<2n), (8)

where and represent the exchange command and the reverse command respectively. According to the definition of , and can be written as and . In this case, equals to . All the components of entry and exit are the same except one, which means has no or only two components that equal to 1. If the -th and -th components of are 1, then exchange command should be performed between and . The exchange command isn’t performed if all components of are 0. For , if the -th component is 1, the reverse command should be performed in the -th position. The executed order of reverse commands doesn’t affect the final result.

For quadrant , , , and are , , and , respectively. According to (7) and (8), equals to and equals to , which mean only exchange command is performed. This simple property guides us design algorithms with lower complexities.

3 Encoding and Decoding Algorithms

The encoding problems are studied first and four encoding algorithms are proposed. Two of them are based on arithmetic operations and the other two bases on bit operations. Then decoding algorithms are obtained similarly. The algorithms either have linear complexity or have constant complexity.

3.1 Encoding Algorithms

Let the level of Hilbert order be . For any point, , each component is written as . The calculated Hilbert order is stored as .

When calculating the Hilbert order, the reverse command is performed first, followed by exchange command. The first encoding algorithm is described in Algorithm 1. We assume and are known, which can be calculated by algorithms in  and be stored.

The Algorithm 1 is an iterative algorithm, which loops from to . It’s evident that for dimensional Hilbert order, the complexity of Algorithm 1 is . For one specific dimension, such as two and three dimensional spaces, the complexity is , which is linear.

Now, let us analyze Algorithm 1. In step (2), the -th component , , is replaced by . This can be achieved by a simple operation. And in step (3), the reverse operation is equivalent to operation. Then algorithm 1 can be rewritten with bit operations, which is described in Algorithm 2.

Algorithm 2 has the same complexity as Algorithm 1. The only difference is that it uses bit operations other than arithmetic operations. The algorithm should be more efficient.

3.2 Encoding Algorithms with Lower Complexities

Now we develop encoding algorithms with lower complexities. According to our analysis above, has two nonzero components, which indicates where exchange command would be performed, and all components of are zero, which means that no inverse command would be performed. From our encoding algorithms above, we can see that only exchange command between and is performed until value of isn’t zero. The is zero all the time. Therefore we can skip part of the loop. This property shows us opportunity to reduce the number of iterations. Assume equals to 0, we define . Then the two encoding algorithms above are rewritten to Algorithm 3 and Algorithm 4 respectively.

Again algorithm 3 is based on arithmetic operations and Algorithm 4 is based on bit operations, which terminate in steps, thus the complexities of them are . For any given point , the is fixed, therefore, the number of iterations of the latter two algorithms are independent of the level of Hilbert curve. For any specific dimension, the complexity is constant. We can see that they are more efficient than the former two when level is much larger than .

3.3 Decoding Algorithms

Let the level of Hilbert curve be . For any integer , it can be written as . Final result is a coordinate, . Decoding procedure is the reverse process of encoding procedure. In the decoding procedure, the exchange command is performed first, then the reverse command. The first decoding algorithms is described in Algorithm 5. Again, each arithmetic operation in Algorithm 5 is equivalent to a bit operation, and a decoding algorithm based on bit operations is proposed by the Algorithm 6.

Algorithm 5 and Algorithm 6 terminate in steps and it’s evident that their complexities are . For any specific dimension , the complexity is linear.

3.4 Decoding Algorithms with Lower Complexities

We introduce the definition of here, which means and . It is the location that the first is not zero. We also assume equals to 1 if equals to 0. It’s equivalent to if we assume equals to 0. isn’t greater than and is independent of . Now we can rewrite Algorithm 5 and Algorithm 6 with lower complexities.

Algorithm 7 and Algorithm 8 terminate in steps and therefore the complexities are . For any fixed input and any specific dimension, the complexity is constant.

4 Discussion

Encoding and decoding algorithms above are concise and easy to implement. In this section, a two dimensional example is employed to illustrate how to use these algorithms. For the sake of simpleness, only Algorithm 1 is studied.

When equals to two, the functions and are calculated and stored in Table 1. Exchange command and reverse command are listed in Table 2, hich are obtained using algorithms introduced in .

Checking Algorithm 1, we can see what steps (2) (4) do is to update coordinate only. The reason we describe the process by using three steps is to make the process clear. In practice, these three steps can be combined together and we use one step to update directly. The updating rules for encoding procedure are shown in Table 3, where is replaced by .

The updating rules can be obtained easily using our algorithm. Take equals to 3 as an example. In this case, is , and is (1, 1). According to our analysis, an exchange operation and two reverse operations should be performed. The new coordinate is after step (2). It is after reverse operation. Then we perform the exchange command, the final coordinate is , which is the same as shown in Table 3. Updating rules for decoding algorithm can be obtained similarly.

In , Chen et al. developed a reduced complexity algorithm for two dimensional case and numerical results were also presented. We implement the three dimensional case in PHG [15, 14], which is an essential module for dynamic load balancing. The Hilbert order algorithms were also implemented in Zoltan . The performance data is collected in Table 4. The first row represents the level of Hilbert order, and others represent running time. ¿From this table, we can see that for a fixed coordinate (1, 1, 1), the computational time increases linearly for algorithm with the complexity while it’s fixed for algorithm with complexity.

5 Conclusion

Encoding and decoding of arbitrary dimension Hilbert order are studied. And the open problem is solved by this paper. Four encoding algorithms and four decoding algorithms are proposed. Four of them have linear computation complexities and the other four have lower complexities. The properties of evolutive rules introduced by  are also studied and some results are deduced, which are applied to develop encoding and decoding algorithms. A two dimensional case is studied and updating rules are presented. By using algorithms developed in this paper, algorithms for any specific dimensional spaces can be obtained. In the end of the paper, numerical experiments are performed, which demonstrate the difference between algorithms with difference complexities.

Acknowledgments

This work is supported by the 973 Program under the grant 2011CB309703, by China NSF under the grants 11021101 and 11171334, by the 973 Program under the grant 2011CB309701, the China NSF under the grants 11101417 and by the National Magnetic Confinement Fusion Science Program under the grants 2011GB105003.

References

•  H. Sagan, Space-Filling Curves. Springer-Verlag; 1994.
•  S. Kamata, R. O. Eason, Y. Bandou, A new algorithm for N-dimensional Hilbert scanning. IEEE Trans on Image Processing 1999; 8(7): 964–973.
•  C. Li, Y. Feng, Algorithm for analyzing n-dimensional Hilbert curve , vol. 3739. Springer Berlin/Heidelberg, 2005; 657–662.
•  A. R. Butz, Altrnative algorithm for Hilbert’s space-filling curve. IEEE Transactions on Computers 1971; 20: 424–426.
•  L. M. Goldschlager, Short algorithms for space-filling curves. Software—Practice and Experience 1981; 11: 99–100.
•  I. H. Witten, B. Wyvill, On the generation and use of space-filling curves. Software—Practice and Experience 1983; 13: 519–525.
•  A. J. Cole, A note on space filling curves. Software—Practice and Experience 1983; 13: 1181–1189.
•  J. G. Griffiths, Table-driven algorithms for generating space-filling curves. Computer-Aided Design 1985; 17(1): 37–41.
•  P. C. Campbell, K. D. Devine, J. E. Flaherty, L. G. Gervasio, J. D. Teresco, Dynamic octree load balancing using space-filling curves. Technical Report CS-03-01 2003.
•  X. Liu, G. F. Schrack, Encoding and decoding the Hilbert order. Software—Practice and Experience 1996; 26(12): 1335–1346.
•  X. Liu, G. F. Schrack, An algorithm for encoding and decoding the 3-D Hilbert order. IEEE transactions on image processing 1997; 6: 1333–1337.
•  A. J. Fisher, A new algorithm for generation hilbert curves. Software: Practice and Experience 1986; 16: 5–12.
•  N. Chen, N. Wang, B. Shi, A new algorithm for encoding and decoding the Hilbert order. Software—Practice and Experience 2007; 37(8): 897–908.
•  H. Liu, Dynamic load balancing on adaptive unstructured meshes. High Performance Computing and Communications, 10th IEEE International Conference on 2008; 0: 870–875.
•  L. Zhang, A Parallel Algorithm for Adaptive Local Refinement of Tetrahedral Meshes Using Bisection, Numer. Math.: Theory, Methods and Applications 2009, 2: 65–89.
•  K. Devine, E. Boman, R. Heaphy, B. Hendrickson, and C. Vaughan Zoltan Data Management Services for Parallel Dynamic Applications, Computing in Science and Engineering, 2002,4,2: 90–97.