One embodiment of the present invention provides a system that implements
a content-addressable memory (CAM) which has multiple banks. During
operation, the system receives a request to insert an item into the CAM,
wherein the request includes a key which is used to index the item and a
body containing data. Next, for each bank in the CAM, the system
calculates a different hash function based on the key to produce an index
and a tag. The system then uses the calculated index and the tag for each
bank to lookup an entry in each bank. If the lookups do not generate a
hit in any bank, the system stores an entry for the request into a
highest priority bank which does not contain a valid entry in the
location accessed by the lookup. In one embodiment of the present
invention, the multiple banks in the CAM have varying sizes.