a method of storing addresses in a database comprising generating original prefixes representing the addresses to be stored in the database . the prefix lengths are determined dynamically . reduced prefixes are generated by collapsing or expanding the original prefixes such that a number of reduced prefixes is less than a number of original prefixes . the reduced prefixes are stored in the database .