## 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 [16], one of the most well-known dynamic load balancing package developed by Sandia National Laboratories. It was also implemented by PHG (Parallel Hierarchical Grid) [15], 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 [1].

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*[13] 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 [14]. 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 [2] and Li et al introduced algorithms for analyzing the properties of -dimensional Hilbert curve [3].

In this paper, we present our work on developing algorithms for encoding and decoding arbitrary high dimensional Hilbert order bases on [3], 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 [3] 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 [3] 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

(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

(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,

(3) |

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

(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(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

(6) |

For the sake of completeness, concepts introduced in [3] 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

[3], 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 [3].### 2.2 Study of Evolutive Rules

Now we analyze the properties of algorithms developed in [3]. Hilbert cell was generated in recursively in [3], 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 [3] 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 [3] can be rewritten as

(7) |

(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.

## 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 [3] 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.

### 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.

### 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.

## 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 [3].

0 | (0, 0) | ||

1 | (0, 1) | ||

2 | (1, 1) | ||

3 | (1, 0) |

(1, 1) | (0, 0) | ||

(0, 0) | (0, 0) | ||

(0, 0) | (0, 0) | ||

(1, 1) | (1, 1) |

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.

Quadrant | ||
---|---|---|

In [13], 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 [16]. 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.

Algorithm | 8 (s) | 32 (s) | 128 (s) | 256 (s) |
---|---|---|---|---|

O(m) | 1.60E-7 | 4.69E-7 | 1.67E-6 | 3.25E-6 |

O(k) | 8.38E-8 | 8.39E-8 | 8.39E-8 | 8.38E-8 |

## 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 [3] 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

- [1] H. Sagan, Space-Filling Curves. Springer-Verlag; 1994.
- [2] 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.
- [3] C. Li, Y. Feng, Algorithm for analyzing n-dimensional Hilbert curve , vol. 3739. Springer Berlin/Heidelberg, 2005; 657–662.
- [4] A. R. Butz, Altrnative algorithm for Hilbert’s space-filling curve. IEEE Transactions on Computers 1971; 20: 424–426.
- [5] L. M. Goldschlager, Short algorithms for space-filling curves. Software—Practice and Experience 1981; 11: 99–100.
- [6] I. H. Witten, B. Wyvill, On the generation and use of space-filling curves. Software—Practice and Experience 1983; 13: 519–525.
- [7] A. J. Cole, A note on space filling curves. Software—Practice and Experience 1983; 13: 1181–1189.
- [8] J. G. Griffiths, Table-driven algorithms for generating space-filling curves. Computer-Aided Design 1985; 17(1): 37–41.
- [9] 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.
- [10] X. Liu, G. F. Schrack, Encoding and decoding the Hilbert order. Software—Practice and Experience 1996; 26(12): 1335–1346.
- [11] 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.
- [12] A. J. Fisher, A new algorithm for generation hilbert curves. Software: Practice and Experience 1986; 16: 5–12.
- [13] 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.
- [14] H. Liu, Dynamic load balancing on adaptive unstructured meshes. High Performance Computing and Communications, 10th IEEE International Conference on 2008; 0: 870–875.
- [15] L. Zhang, A Parallel Algorithm for Adaptive Local Refinement of Tetrahedral Meshes Using Bisection, Numer. Math.: Theory, Methods and Applications 2009, 2: 65–89.
- [16] 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.

Comments

There are no comments yet.