i
i
i
i
i
i
i
i
14.1. Spatial Data Structures 657
14.1.4 Cache-Oblivious and Cache-Aware
Representations
Since the gap between the bandwidth of the memory system and the com-
puting power of CPUs increases every year, it is very important to de-
sign algorithms and spatial data structure representations with caching in
mind. In this section, we will give an introduction to cache-aware (or cache-
conscious) and cache-oblivious spatial data structures. A cache-aware rep-
resentation assumes that the size of cache blocks is known, and hence we
optimize for a particular architecture. In contrast, a cache-oblivious algo-
rithm is designed to work well for all types of cache sizes, and are hence
platform-independent.
To create a cache-aware data structure, you must first find out what
the size of a cache block is for your architecture. This may be 64 bytes,
for example. Then try to minimize the size of your data structure. For
example, Ericson [315] shows how it is sufficient to use only 32 bits for a k-
d tree node. This is done in part by appropriating the two least significant
bits of the node’s 32-bit value. These two bits can represent four types: a
leaf node, or the internal node split on one of the three axes. For leaf nodes,
the upper 30 bits hold a pointer to a list of objects; for internal nodes, these
represent a (slightly lower precision) floating point split value. Hence, it
is possible to store a four-level deep binary tree of 15 nodes in a single
cache block of 64 bytes (the sixteenth node indicates which children exist
and where they are located). See his book for details. The key concept is
that data access is considerably improved by ensuring that structures pack
cleanly to cache boundaries.
One popular and simple cache-oblivious ordering for trees is the van
Emde Boas layout [32, 315, 1296]. Assume we have a tree, T ,withheight
h. The goal is to compute a cache-oblivious layout, or ordering, of the
nodes in the tree. Let us denote the van Emde Boas layout of T as v(T ).
This structure is defined recursively, and the layout of a single node in a
tree is just the node itself. If there are more than one node in T ,thetreeis
split at half the height, h/2. The topmost h/2 levels are put in a tree
denoted T
0
, and the children subtree starting at the leaf nodes of T
0
are
denoted T
1
,...,T
n
. The recursive nature of the tree is described as follows:
v(T )=
{T } , if there is single node in T ,
{T
0
, T
1
,...,T
n
} ,else.
(14.2)
Note that all of the subtrees T
i
,0≤ i ≤ n, are also defined by the recursion
above. This means, for example, that T
1
has to be split at half its height,
and so on. See Figure 14.7 for an example.
In general, creating a cache-oblivious layout consists of two steps: clus-
tering and ordering of the clusters. For the van Emde Boas layout, the