A Content Addressable Memory (CAM) or Ternary CAM (TCAM) provides error
detection and correction (EDAC). EDAC codes are chosen based on logical
and physical properties of the CAM/TCAM. An entry in the CAM/TCAM
comprises a plurality of groups, each group comprising a plurality of
storage bits. Writes to the storage bits are encoded to enable EDAC.
Lookup data is divided into lookup groups of one or more bits, and is
applied to corresponding groups of entries to be searched. In one
embodiment, storage bits in a group are first decoded to detect and/or to
correct errors and then compared with a lookup group to produce a hit
indication. In another embodiment, storage bits in a group are logically
combined with a lookup group to produce a hit indication, wherein a
correctable error in the storage bits does not affect correctness of the
hit indication.