Methods and apparatus are disclosed for mapping prefixes and/or values of
a hierarchical space to other representations while maintaining the original hierarchy,
which may be especially useful in conjunction with associative memories, such as
binary and ternary content-addressable memories. In one implementation, a set of
prefixes associated with a hierarchical space is received. A new representation
of the set of prefixes is developed, such as by using a trie representation, with
the new representation maintaining the original hierarchical relationship. This
new representation may be an optimized representation selected to reduce or minimize
the depth of the trie or some other cost. A set of new prefixes are generated along
with a set of lookup values. During processing, a value, such as that included
in a packet, is converted to one of the lookup values, which is used to generate
a lookup word for use in matching against the new prefixes.