Abstract:
The present invention increases the efficiency of performing longest prefix matching operations by selecting a radix-encoded trie structure optimized with respect to memory cost. The structure is optimized by determining memory costs for retrie structures indexed on different numbers of high-order characters, and then selecting the structure corresponding to the lowest memory cost. The optimization improves performance in IP look-up operations as well as longest-prefix matching operations performed on general alphabets.

Description:
This application claims the benefit of U.S. provisional application No. 60/350,711, filed on Nov. 13, 2001, the contents of which are fully incorporated herein by reference. 
   This application is a continuation-in-part of U.S. patent application Ser. No. 09/603,154 filed on Jun. 23, 2000, now U.S. Pat. No. 6,928,485 which claims the benefit of U.S. provisional application No. 60/151,194 filed Aug. 27, 1999, the contents of which are fully incorporated herein by reference. 

   FIELD OF THE INVENTION 
   The present invention relates generally to fast prefix matching, and, more particularly, to the use of dynamic programming for optimizing a radix encoded trie structure used for prefix look-up. The disclosed methods have uses including IP routing, network clustering and telephone marketing. 
   BACKGROUND OF THE INVENTION 
   Longest Prefix Matching (LPM) is the problem of determining from a set of strings the longest one that is a prefix of some other, given string. LPM is at the heart of many important applications. Internet Protocol (IP) routers routinely forward packets by computing from their routing tables the longest bit string that forms a prefix of the destination address of each packet. In copending U.S. patent application Ser. No. 09/603,154, filed Jun. 23, 2000 and entitled “Network-Aware Clustering of Web Clients,” Krishnamurthy and Wang describe a method for clustering Web clients by identifying a set of IP addresses that with high probability are under common administrative control and topologically close together. Such clustering information has applications ranging from network design and management to providing on-line quality of service differentiation based on the origin of a request. The proposed clustering approach is network aware in that addresses are grouped based on prefixes in snapshots of border gateway protocol (BGP) routing tables. 
   Telephone network management and marketing applications often classify regions in the country by area codes or combinations of area codes and the first few digits of the local phone numbers. For example, the state of New Jersey is identified by area codes such as 201, 908, and 973. In turn, Morris County in New Jersey is identified by longer telephone prefixes like 908876 and 973360. Those applications typically require computing in seconds or minutes summaries of calls originating and terminating at certain locations from daily streams of telephone calls, up to hundreds of millions records at a time. That requires very fast classification of telephone numbers by finding the longest matching telephone prefixes. 
   LPM solutions must be considered in the context of the intended use to maximize performance. The LPM applications discussed above have some common characteristics: 
   1. Look-ups overwhelmingly dominate updates of the prefix sets. A router may route millions of packets before its routing table changes. Similarly, telephone number classifications rarely change, but hundreds of millions of phone calls are made daily. 
   2. The look-up rate is extremely demanding. IP routing and clustering may require worst-case LPM performance of a couple hundred nanoseconds per look-up. That severely limits the number of machine instructions and memory references allowed. 
   3. Prefixes and strings are bounded in length and based on small alphabets. For example, current IP addresses are 32-bit strings and U.S. telephone numbers are 10-digit strings. 
   The first two characteristics mean that certain theoretically appealing solutions based on, e.g., suffix trees, string prefix matching or dynamic string searching are not applicable, as their performance would not scale. Fortunately, the third characteristic means that specialized data structures can be designed with the desired performance levels. In the present application, the inventors disclose a system and method that may be generalized to bounded strings such as telephone numbers. 
   The present application discloses retries, a novel, fast, and compact data structure for LPM on general alphabets. Simulation experiments based on trace data from real applications show that retries outperform other published data structures for IP routing. By extending LPM to general alphabets, retries also admit new applications that could not exploit prior LPM solutions designed for IP look-ups. 
   The popularity of the Internet has made IP routing an important area of research. Several LPM schemes for binary strings have been disclosed in this context. For example, the idea of using ranges induced by prefixes to perform IP look-ups was suggested in B. Lampson, V. Srinivasan, &amp; G. Varghese, “IP Lookups Using Multiway and Multicolumn Search,” IEEE/ACM Trans. Netwk., 7(3):324–34 (1999). The authors of that paper describe a method for routing Internet packets exploiting a simple relationship between IP prefixes and nested intervals of natural numbers. That method was later analyzed by Gupta, Prabhakar, and Boyd in “Near-Optimal Routing Lookups with Bounded Worst Case Performance,” Proc. 19th IEEE INFOCOM, vol. 3, p. 1184–92 (2000), to guarantee worst-case performance. The method, however, is not generalized to other instances of LPM such as non-binary strings and arbitrary alphabets. 
   Multi-level table look-up schemes are used for both hardware and software implementations for IP routing. Since modern machines use memory hierarchies with sometimes dramatically different performance levels, some implementations attempt to build data structures conforming to the memory hierarchies at hand. Both the LC (level compression)-trie scheme of S. Nilsson &amp; G. Karlsson, “IP-Address Lookup Using LC-Tries,” IEEE J. Sel. Area. Comm., 17(6):1083–92 (1999), and the multi-level table of V. Srinivasan &amp; G. Varghese, “Fast Address Lookup Using Controlled Prefix Expansion,” ACM Trans. Comp. Sys., 17(1):1–40 (1999), attempt to optimize for L2 caches by adjusting the number of levels to minimize space usage. Efficient implementations, however, exploit the binary alphabet of IP addresses and prefixes. 
   G. Cheung &amp; S. McCanne, “Optimal Routing Table Design for IP Address Lookup Under Memory Constraints,” Proc. 18th IEEE INFOCOM, vol. 3, p. 1437–44 (1999), took a more general approach to dealing with memory hierarchies that includes the use of prefix popularity. Those authors consider a multi-level table scheme similar to retries and attempt to minimize the space usage of popular tables so that they fit into the fast caches. Since the cache sizes are limited, they must solve a complex constrained optimization problem to find the right data structure. L1 caches on most machines are very small, however, so much of the gain comes from fitting a data structure into L2 caches. In addition, the popularity of prefixes is a dynamic property and not easy to approximate statically. Cheung &amp; McCanne do not focus on bounding the number of memory accesses and minimizing memory usage. 
   P. Crescenzi, L. Dardini &amp; R. Grossi, in “IP Address Lookup Made Fast and Simple,” Proc. 7th ESA, vol. 1643 of LNCS, p. 65–76, Springer-Verlag (1999), proposed a compressed-table data structure for IP look-up. The key idea is to identify runs induced by common next-hops among the 2 32  implicit prefixes to compress the entire table with that information. The technique works well when the number of distinct next-hops is small and there are few runs, which is mostly the case in IP routing. The compressed-table data structure is fast, because it bounds the number of memory accesses per match. Unfortunately, in network clustering applications, both the number of distinct next-hop values and the number of runs can be quite large. Thus, that technique is not practical in such applications. 
   It is therefore desirable to provide a method for fast prefix matching that may be generalized for arbitrary alphabets, uses a limited amount of memory and does not involve solving complex optimization problems. 
   SUMMARY OF THE INVENTION 
   The present invention addresses those needs by providing a method for optimizing a retrie table for matching prefixes. 
   One embodiment of the invention is a method for building a radix-encoded trie structure for a set P of bounded strings. According to the method, for each of a plurality of integer values i, a memory cost is determined for a radix-encoded trie structure having a first level indexed on i highest order characters of the strings of set P. One of the plurality of integer values i, corresponding to a lowest memory cost, is selected. A radix-encoded trie structure is then built for the strings of set P, the structure having a first level indexed on i highest-order characters of the strings. 
   In that method, the step of determining a memory cost for a radix-encoded trie structure may include computing a sum of a memory cost of internal table entries; a memory cost of data entries for strings of set P having a length no greater than i; and a memory cost of radix-encoded trie sub-structures for strings of set P having a length greater than i. 
   The step of determining a memory cost for a radix-encoded trie structure may include computing a memory cost of internal table entries equal to c t α i , wherein c t  is a cost of an internal table entry and α is an alphabet size used in the strings of set P. 
   The step of determining a memory cost for a radix-encoded trie structure may further include computing a memory cost of data entries for strings of set P having lengths no greater than i, the cost being equal to c d |P ≦i |, wherein C d  is a cost of a data entry and P ≦i  is a subset of the strings of set P comprising strings having lengths no greater than i. 
   The step of determining a memory cost for a radix-encoded trie structure may further include computing a memory cost of radix-encoded trie sub-structures for each subset Q of set P comprising strings having a length greater than i and having i identical high-order characters, the cost being equal to Σ QεL(P,t) S(strip(Q,i),k−1), wherein L(P,i) is a partition of those strings of set P having lengths greater than i, into equivalence classes induced by i high-order characters, strip(Q,i) is a set of the strings of Q with i high-order characters stripped off, k is a number of levels in the radix encoded trie structure, and S(strip(Q,i),k−1) computes a size of a trie sub-structure for strip(Q,i) having k−1 levels. 
   The method may also include the step of modifying the set P of bounded strings by first deriving a set of disjoint intervals from the strings, and then redefining the set P from the disjoint intervals. 
   Further, the method may include the step of instantiating the radix-encoded trie structure in one or more superstrings. In that case, the step of instantiating the trie structure in superstrings may comprise merging left and right ends of leaf tables of the trie structure in best-fit order, or may comprise computing the superstrings using a greedy shortest common superstring approximation. 
   In another embodiment of the invention, a machine readable medium is provided, containing configuration instructions for performing the above-described method. 
   In still another embodiment of the invention, a method is provided for building a radix-encoded trie structure for a set of string prefixes. That method includes the step of forming an interval set by associating with each string prefix of the prefix set an interval containing strings that begin with the string prefix. A disjoint interval set is formed by, where a first of said intervals is contained in a second of said intervals, replacing the first interval with at most two new intervals contained in the first interval and outside the second interval. A new set of string prefixes is then constructed from the disjoint interval set. A radix-encoded trie structure is selected for the new set of prefixes, the structure corresponding to a lowest memory cost. The selected radix-encoded trie structure is then built for the new set of prefixes. 
   In that embodiment, the step of selecting a radix-encoded trie structure may include, for each of a plurality of integer values i, determining a memory cost for a radix-encoded trie structure having a first level indexed on i highest order bits of the prefixes in the new set of prefixes and selecting a value of i corresponding to a lowest memory cost. In that case, the step of building the selected radix-encoded trie structure includes building a structure having a first level indexed on i highest-order bits of the prefixes. 
   The method may also include the step of sorting the intervals of the interval set by low ends before forming the disjoint interval set. In that case, the sorting step may include breaking ties by taking longer intervals first. 
   The method may also include the step of instantiating the radix-encoded trie structure in one or more superstrings. The step of instantiating the trie structure may comprise merging left and right ends of leaf tables of the trie structure in best-fit order, or may comprise computing the superstrings using a greedy shortest common superstring approximation. 
   These and other advantages of the invention will be apparent to those of ordinary skill in the art by reference to the following detailed description and the accompanying drawings. 

   
     BRIEF DESCRIPTION OF THE DRAWINGS 
       FIG. 1  is a table showing a prefix set and corresponding intervals. 
       FIG. 2  is a listing of code for constructing prefixes covering an interval. 
       FIG. 3  is a listing of code for searching a retrie for a longest prefix. 
       FIG. 4  is a table showing a retrie data structure. 
       FIG. 5  is a table of data used in an IP routing experiment. 
       FIG. 6  is a table of results of an IP routing experiment. 
       FIG. 7  is a table showing data structure sizes in a clustering experiment. 
       FIG. 8  is a table of results of a clustering experiment. 
       FIG. 9  is a table of results of a telephone number classification experiment. 
   

   DETAILED DESCRIPTION 
   Referring to  FIG. 1 , a sample prefix set  110  is illustrated by showing four strings using a binary alphabet A={0,1} and maximum string length m=8; i.e., 8-bit strings. Values  120  are data stored in association with each of the strings. For example, the first string  111  in the set would best match the string 00100101, yielding result a. On the other hand, the second string  112  would best match 00101101, yielding b. 
   Let A be an alphabet of finite size a α=δ+1. Without loss of generality, assume that A is the set of natural numbers in the range [0,δ]. Otherwise, map A&#39;s elements to their ranks in any fixed, arbitrary order. Then, the elements of A may be thought of as digits in base α so that a string s=s 1 s 2  . . . s k  over A represents an integer ν=s 1 α k−1 +s 2 α k−2 + . . . +s k . The functions t and σ are defined so that t(s)=ν and σ(ν)=s. When working with fixed length strings, σ(ν) have enough 0&#39;s padded on the left to gain that length. For example, when the string 1001 represents a number in base 2, t(01001) is the decimal value 9. Conversely, in base 3 and with prescribed length 6, σ(9) is the string 000100. Clearly, for any two strings s and t with equal lengths, t(s)&lt;t(t) if and only if s precedes t lexicographically. 
   Longest Matching Prefixes and Shortest Containing Intervals 
   Let m be some fixed integer. Consider A ≦m  and A m , respectively, the sets of strings over A with lengths ≦m and lengths exactly equal to m. Let P ⊂ A ≦m , and with each pεP let there be associated a data value; the data values need not be mutually distinct. We define an LPM instance (A, m) as the problem of finding the data value associated with the longest string in P that is a prefix of some string sεA m . P is commonly called the prefix set, and its elements are called prefixes. Following a convention in IP routing, strings shall be denoted s/k where s is a string and k≦len(s) to mean the prefix of s with k digits. 
   For any string s in A ≦m , let s 0 =s0 . . . 0 and s δ =sδ . . . δ a be two strings in which enough 0&#39;s and δ&#39;s are used to pad s to length m. Using the above correspondence between strings and integers, s can be associated with the closed interval of integers [t(s 0 ),t(s δ )]. That interval is denoted I(s), and its length is t(s δ )−t(s 0 )+1. 
   Now let ν be in I(s), and consider the string σ(ν), 0-padded on the left to be length m. By construction, σ(ν) must agree with s 0  and s 67  up to the length of s. On the other hand, if ν&lt;t(s 0 ), then σ(ν) lexicographically precedes s 0 , so s cannot be a prefix of σ(ν). A similar argument applies when ν&gt;t(s δ ). It therefore follows that: 
   LEMMA 1: Let s be a string in A ≦m  and ν&lt;α m . Then s is a prefix of σ(ν) if and only if ν is in I(s). 
   For any prefix set P, I(P) is used to denote the set of intervals associated with prefixes in P. Now consider two prefixes p 1  and p 2  and their corresponding intervals I(p 1 ) and I(p 2 ). Applying Lemma 1 to the endpoints of those intervals shows that either the intervals are completely disjoint or one is contained in the other. Furthermore, I(p 1 ) contains I(p 2 ) if and only if p 1  is a prefix of p 2  Next, when s has length m, t(s 0 )=t(s δ )=t(s). Lemma 1 asserts that if p is a prefix of s then I(P) must contain t(s). The nested property of intervals in a prefix set P then gives: 
   THEOREM 2: Let P be a prefix set and s a string in A m . Then p is the longest prefix matching s if and only if I(p) is the shortest interval in I(P) containing t(s). 
   Column  130  of  FIG. 1  shows the correspondence between prefixes and intervals. For example, the string 00101101 with numerical value 45 would have [40,47] as the shortest containing interval, giving b as the matching result. 
   Two intervals that are disjoint or nested are called nested intervals. Theorem 2 enables treating the LPM problem as that of managing a collection of mutually nested intervals with the following basic operations: 
   Insert inserts a new interval [a,b] with some associated data value ν. If [a,b] intersects an existing interval, it is required that [a,b] is contained in or contains that interval. 
   Retract deletes an existing interval [a,b] from the current set of intervals. 
   Get gets, for a integer value p, the value associated with the shortest interval, if any, that contains p. 
   When m and α are small, the integers arising from strings and interval endpoints are storable in standard computer integer types. As described in more detail below, that allows construction of practical data structures for LPM based on integer arithmetic. 
   Equivalence Among LPM Instances and Prefix Sets 
   A data structure solving an (A,m) instance can sometimes be used for other instances, as follows. Let (B,n) be another instance of the LPM problem with β the size of B and n the maximal string length. Suppose that α m ≧β n . Since the integers corresponding to strings in β ≦n  are less than α m , they can be represented as strings in A ≦m . Furthermore, let I(p) be the interval corresponding to a prefix p in B ≦n . Each integer in I(p) can be considered an interval of length 1, so it is representable as a prefix of length m in A ≧m . Thus, each string and prefix set in (B,n) can be translated into some other string and prefix set in (A,m). It therefore follows: 
   THEOREM 3: Let (A,m) and (B,n) be two instances of the LPM problem in which the sizes of A and B are α and β respectively. Then any data structure solving LPM on (A,m) can be used to solve (B,n) as long as α m ≧β n . 
   That use of single values in an interval to generate prefixes is inefficient. Let [lo,hi] be some interval where lo&lt;α m  and hi&lt;α m .  FIG. 2  shows an algorithm (in C) for constructing prefixes from [lo,hi]. A simple induction argument on the quantity hi−lo+1 shows that the algorithm constructs the minimal set of subintervals covering [lo,hi] such that each subinterval corresponds to a single prefix in A ≦m . We assume an array A[ ] such that A[i] has the value α i . The function itvl2pfx( ) converts an interval into a prefix by inverting the process of mapping a prefix into an interval described earlier. Note that such a prefix will have length m−i. 
   Given a nested set of intervals I, it is possible to construct a minimal set of prefixes P(I) such that (1) I(p) and I(q) are disjoint for p≠q; and (2) finding the shortest interval in I containing some integer i is the same as finding the longest prefix in P(I) matching σ(i). That is done as follows: 
   1. Sort the intervals in I by their low ends, breaking ties by taking longer intervals first. The nested property of the intervals means that [i, j]&lt;[k,l] in this ordering if j&lt;k or [i, j] contains [k,l]. 
   2. Build a new set of intervals by adding the sorted intervals in order. When an interval [i, j] is added, if it is contained in some existing interval [k,l], then in addition to adding [i, j], replace [k,l] with at most two new disjoint intervals, [k,i−1] and [j+1,l], whenever they are of positive length. 
   3. Merge adjacent intervals that have the same data values. 
   4. Apply the algorithm of  FIG. 2  to each of the resulting intervals to construct the new prefixes. 
   Column  140  of  FIG. 1  shows how the nested intervals are split into disjoint intervals. Those intervals are then transformed into a new collection of prefixes, shown in column  150 . Data values  160  are assigned to the new prefixes according to the original assignments. A property of the new prefixes is that none of them can be a prefix of another. 
   In the remainder of the present discussion, each considered prefix set P shall represent disjoint intervals. If not, that prefix set is converted into the equivalent set of prefixes P(I(P)) as discussed. 
   The Retrie Data Structure 
   Theorem 3 asserts that any LPM data structure for one type of string can be used for other LPM instances as long as alphabet sizes and string lengths are within bounds. For example, 15-digit international telephone numbers fit in 64-bit integers, so data structures for fast look-ups of IPv4 32-bit addresses are potentially usable, with proper extensions, for telephone number matching. Unfortunately, many of those data structures are too highly tuned for IP routing to be effective in the other applications considered herein, such as network address clustering and telephone number matching. A retrie data structure is therefore described below for fast LPM queries in A ≦m . 
   Let P be a prefix set in A ≦m . Each prefix in P is associated with some data value, an integer in a given range [0,D]. We could build a table of size α m  that covers the contents of the intervals in P. Then, the LPM of a string can be looked up with a single index. Such a table would be impossibly large, however, for interesting values of α and m. We therefore build a smaller, recursively structured table, which we call a radix-encoded trie (or retrie). The top level table is indexed by some number of left digits of a given string. Each entry in this table points to another table, indexed by some of the following digits, and so on. As such, there are two types of tables: internal and leaf. An entry of an internal table has a pointer to the next level table and indicates whether that table is an internal or leaf table. An entry of a leaf table contains the data associated with the prefix matched by that entry. All internal tables are kept in a single array Node, and all leaf tables are kept in a single array Leaf. 
   Described below is a technique for minimizing the space used by the entire retrie. The size of a leaf entry depends on the maximum of the data values associated with the given prefixes. For example, if the maximum data value is &lt;2 8 , then a leaf entry may be stored in a single byte while a maximum data value between 2 8  and 2 16  means that leaf data must be stored using 2 bytes, and so on. For fast computation, the size of an internal table entry is chosen so that the entry would fit in some convenient integer type. The bits of that type are partitioned into three parts (pbits, ibit, bbits) as follows. The first pbits bits define the number of digits used to index the next level table, which thus has α pbits  entries. The single ibit bit is either 1, indicating that the next level is internal, or 0, indicating that the next level is leaf. The last bbits bits define the offset into the Node or Leaf array at which the next level table begins. 
   In a currently preferred embodiment, 32-bit integers are used for internal table entries with the partition (5, 1, 26). Up to 31 digits can thus be used to index a table, and the maximal number of entries in the arrays Node and Leaf is 2 26 . That is ample for the herein-described applications. For larger applications, 64-bit table entries can be used with some other appropriate bit partitions. 
   Given a retrie built for some prefix set P ⊂ A ≦m , let root be a single internal table entry whose bits are initialized to tell how to index the top level table. Let A[ ] be an integer array such that A[i]=α i . Now let s be a string in A m  with integer value sν=t(s).  FIG. 3  shows an algorithm to compute the data value associated with the LPM of s. 
     FIG. 4  shows a 3-level retrie for the prefix set shown in column  150  of  FIG. 1 . The Node array begins with the top-level internal table  410 . Indices  412  to the left of table entries are in binary and with respect to the head of the corresponding table within the Node or Leaf array. Each internal table entry has three parts  420 ,  422 ,  424  as discussed. All internal table entries without the third part go to the same leaf table entry that has some default value for strings without any matching prefix. For example, the string 00101101 is matched by first stripping off the starting 2 bits  00  to index entry 0 (row  431 ) of the top level table (rows  430 ). The ibit of that entry is 1, indicating that the next level is another internal table. The third part, bbits, of the entry  431  points to the base (rows  440 ) of that table. The pbits of the entry  431  indicate that one bit should be used to index the next level. Then, the indexed entry (row  441 ) in the next level table points to a leaf table  450 . The entries of that table are properly defined so that the fourth and fifth bits of the string, 01, index the entry with the correct data, b (row  451 ). 
   A retrie with k levels enables matching with at most k indexing operations. That guarantee is important in applications such as IP forwarding. Smaller k&#39;s mean larger look-up tables, so it is important to ensure that a retrie with k levels uses minimal space. We next discuss how to do this using dynamic programming. 
   Given a prefix set P, define len(P)=max{len(p): pεP}. For 1≦i≦len(P), let P ≦i  be the subset of prefixes with lengths ≦i. Then, let L(P,i) be the partition of P−P ≦i  into equivalence classes induced by the left i digits. That is, each part Q in L(P,i) consists of all prefixes longer than i and having the same first i digits. Now, let strip(Q,i) be the prefixes in Q with their left i digits stripped off. Such prefixes represent disjoint intervals in the LPM instance (A,m−i). Finally, let C d  be the size of a data (leaf table) entry and c t  the size an internal table entry. The following dynamic program computes S(P,k), the optimal size of a retrie data structure for a prefix set P using k levels. 
   If P=0 or k=1, then
 
 S ( P,k )= c   d α len(P) .
 
   Otherwise,
 
 S ( P,k )=min{c d α len(P) ,min 1≦i&lt;len(P)   {c   t α i   +c   d   |P   ≦i |+Σ QεL(P,t)   S (strip( Q,i ), k− 1)}}.
 
   The first case states that a leaf table is built whenever the prefix set is empty or only a single level is allowed. The second case recurses to compute the optimal retrie and its size. The first part of the minimization considers the case when a single leaf table is constructed. The second part of the minimization considers the cases when internal tables may be constructed. In these cases, the first term c t α i  expresses the size of the constructed internal table to be indexed by the first i digits of a string. The second term c d |P ≦i | expresses the fact that each prefix short enough to end at the given level requires a single leaf table entry for its data value. The last term Σ QεL(P,t) S(strip(Q,i),k−1) recurses down each set strip(Q,i) to compute a retrie with optimal size for it. 
   Each set strip(Q,i) is uniquely identified by the string formed from the digits stripped off from the top level of the recursion until strip(Q,i) is formed. The number of such strings is bounded by |P|len(P). Each such set contributes at most one term to any partition of the len(P) bits in a prefix. For k≦len(P), the dynamic program examines all partitions of [1,len(P)] with ≦k parts. The number of such partitions is O(len(P) k−1 ). Thus, we have: 
   THEOREM 4: The cost to compute S(P,k) is O(|P|len(P) k ). 
   In practice, len(P) is bounded by a small constant, e.g., 32 for IP routing and 10 for U.S. phone numbers. Since the number of levels cannot exceed len(P), the dynamic program essentially runs in time linear in the number of prefixes. 
   The internal and leaf tables are sequences of elements. In the dynamic program, each table is considered to be instantiated in the Node or Leaf array as it is created. Memory usage is reduced by exploiting redundancies, especially in the leaf tables. For example, in IP routing, the leaf tables often contain many similar, long runs of relatively few data values. Computing a short superstring of the tables reduces space very effectively. Three possible heuristics were considered by the inventors: 
   1. The trivial superstring is formed by catenating the leaf tables. 
   2. The left and right ends of the leaf tables are merged in best-fit order. 
   3. A superstring is computed using a standard greedy SCS (Shortest Common Superstring) approximation. 
   Both methods 2 and 3 effectively reduce space usage, as shown below. In practice, however, the second method gives the best trade-off between computation time and space reduction. 
   Finally, it is possible to add superstring computation of leaf tables in the dynamic program to estimate more accurately the actual sizes of the leaf tables. That would better guide the dynamic program to select an optimal overall lay-out. The high cost of superstring computation, however, makes this impractical. Thus, the superstring lay-out of leaf tables is done only after the dynamic program finishes. 
   Applications and Performance 
   The inventors have considered three applications of the present invention: IP routing, network clustering, and telephone marketing. Each application exhibits different characteristics. In current IP routing, the strings are 32 bits long, and the number of distinct data values, i.e., next-hops, is small. For network clustering, several BGP tables are merged together and either the prefixes or their lengths are used as data values so that after a look-up, the matching prefix itself is retrieved. In that case, either the number of data values is large or there are many runs of data values. For routing and clustering, retries are compared to LC-tries, and to the compressed-table data structure of Crescenzi, Dardini, and Grossi (see above). The authors&#39; code for both benchmarks was used. The inventors&#39; test suite included the FUNET router table and traffic trace used in the LC-trie work. Those data structures are designed specifically for IP prefix matching. The third application is telephone marketing, in which strings are telephone numbers. 
     FIG. 5  is a table summarizing the routing tables  510  used by the inventors in testing the invention as applied to IP routing. It reports how many distinct prefixes  520  and next-hops  530  each routing table contained and the sizes  540  of the data structures built on each. Retrie-FL (rsp, -LR; -GR) is a depth-2 retrie with catenated (rsp., left-right, best-fit merge; greedy) record layout. For routing, depth was limited to 2 to emphasize query time. The inventors used deeper retries in network clustering tests described below. 
   The LPM query timing was engendered by router traffic. Since the real traffic traces were not available for the tables other than ATT and FUNET, the inventors constructed random traces by choosing, for each table, 100,000 prefixes uniformly at random (with replacement) and extending them to full 32-bit addresses. Each random trace was used as generated and also with the addresses sorted lexicographically to present locality that might be expected in a real router. Random traces were generated for the ATT and FUNET tables as well, to juxtapose real and random data. Each trace was processed through the respective table 100 times, measuring average LPM query time; each data structure was built from scratch for each unique prefix table. Data structure build times are also reported. 
   The inventors performed the evaluation on an SGI Challenge and a Pentium. The SGI ran IRIX 6.5 on a 400 MHz R12000 with split 32 KB L1 data and instruction caches, 8 MB unified L2 cache, and 12 GB main memory. The Pentium ran Linux 2.4.6 on a 1 GHz Pentium III with split 16 KB L1 data and instruction caches, 256 KB unified L2 cache, and 256 MB main memory. Each time reported is the median of five runs.  FIG. 6  is a table reporting the results. 
   LC-tries were designed to fit in L2 cache and do so on all the tables on the SGI but none on the Pentium. Retries behave similarly, although they were not designed to be cache resident. CDG fits in the SGI cache on AADS, FUNET, MAE-WEST, and PAIX. Retries uniformly outperformed LC-tries, sometimes by an order of magnitude, always by a factor exceeding three. CDG outperformed retries only on some of the FUNET traces on the Pentium. For that table, the numbers of prefixes and next-hops were relatively low, and CDG is sensitive to those sizes. On the larger tables (OREGON and TELSTRA), retries significantly outperformed CDG. As routing tables are continually growing, with 250,000 entries expected by 2005, it is expected that retries will outperform CDG on real data. Furthermore, the FUNET trace was filtered to zero out the low-order 8 bits of each address for privacy purposes and thus is not a true trace for the prefix table, which contains some entries longer than 24 bits. 
   The data suggest that the non-trivial superstring retrie variations significantly reduce the space of the data structure. As might be expected, the greedy superstring approximation is comparatively slow, but the best-fit merge runs with little time degradation over the trivial superstring method and still provides significant space savings. 
   There is a nearly uniform improvement in look-up times from retrie-FL to retrie-LR to retrie-GR even though each address look-up performs exactly the same computation and memory accesses in all three cases. That suggests beneficial effects from the hardware caches. The improvement is likely due to the overlapping of leaf tables in retrie-LR and retrie-GR, which both minimizes space usage and increases the hit rates for similar next-hop values. 
   The data also suggest that LPM queries on real traces run significantly faster than on random traces. Again that suggests beneficial cache effects, from the locality presented by IP routing traffic. Real trace data is thus critical for accurate measurements, although random data seem to provide an upper bound to real-world performance. 
   Finally, while retries take longer to build than LC-tries (and sometimes CDG), build time (for -FL and -LR) is acceptable, and query time is more critical to routing and on-line clustering, which is assessed next. 
   In analyzing the present invention as applied to network clustering, the routing tables used above were combined. There are 168,161 unique network addresses in the tables. The goal of clustering is to recover the actual matching prefix for an IP address, thereby partitioning the addresses into equivalence classes. PREF assigns each resulting prefix itself as the data value. LEN assigns the length of each prefix as its data value, which is sufficient to recover the prefix, given the input address. PREF, therefore, has 168,161 distinct data values, whereas LEN has only 32. 
   The inventors built depth-2 and -3 retries and LC-tries for PREF and LEN.  FIG. 7  is a table detailing the data structure sizes. There is a significant difference in retrie sizes for the two tables PREF  710  and LEN  720 . The relative sparseness of data values in LEN produces a much smaller Leaf array, which can also be more effectively compressed by the superstring methods. Further, the space reduction achieved by depth-3 retries  740  compares favorably to that achieved by depth-2 retries  730 . Depth-3 retries are smaller than LC-tries for this application, yet, as shown below, outperform the latter. CDG could not be built on either PREF or LEN. CDG assumes a small number of next-hops and exceeded memory limits for PREF on both machines. CDG failed on LEN, because the number of runs of equal next-hops was too large. Here the difference between the IP routing and clustering applications of LPM becomes striking: retries work for both applications, but CDG cannot be applied to clustering. 
   Build times and query times for clustering of Apache and EW3 server logs are shown in the table of  FIG. 8 . Apache contains IP addresses recorded at www.apache.org. The 3,461,361 records gathered in late 1997 had 274,844 unique IP addresses. EW3 contains IP addresses of clients visiting three large corporations whose content were hosted by AT&amp;T&#39;s Easy World Wide Web. Twenty-three million entries were gathered for the analysis, representing 229,240 unique IP addresses. The experimental setup was as in the routing assessment. Clustering is an on-line application: the data structures are built once (e.g., daily), and addresses are clustered as they are processed, e.g., by a web server. Thus, query time is paramount. Retries significantly outperform LC-tries for this application, even at depth 3, as shown in  FIG. 8 . 
   In testing the telephone marketing application of the invention, the market was divided into regions, each of which is identified by a set of telephone prefixes. Given daily traces of telephone calls, the application classifies the callers by regions, updates usage statistics, and generates a report. Such reports may help in making decisions on altering the level of advertisement in certain regions. For example, the set of prefixes identifying Morris County, N.J., includes 908876 and 973360. Thus, a call originating from a telephone number of the form 973360XXXX would match Morris County, N.J. 
   The table of  FIG. 9  shows performance results (on the above SGI) from using a retrie to summarize telephone usage in different regions of the country for a six-month period. The second column  910  shows the number of call records per month that were used in the experiment. Since this application is off-line, we consider the total time required to classify all the numbers. The third column  930  shows that time (in seconds) for retries, and the fourth column  940  contrasts the time using a binary search approach for matching. The table shows the benefit of using retries in a telephone marketing application. Previous IP look-up data structures do not extend to this alphabet. 
   The foregoing Detailed Description is to be understood as being in every respect illustrative and exemplary, but not restrictive, and the scope of the invention disclosed herein is not to be determined from the Detailed Description, but rather from the claims as interpreted according to the full breadth permitted by the patent laws. It is to be understood that the embodiments shown and described herein are only illustrative of the principles of the present invention and that various modifications may be implemented by those skilled in the art without departing from the scope and spirit of the invention. For example, the detailed description has been described with particular emphasis on network routing, network clustering and telephone marketing. However, the principles of the present invention could be extended to any bounded prefix matching problem involving strings using any alphabet. Such an extension could be readily implemented by one of ordinary skill in the art given the above disclosure.