TERNARY content addressable memories (TCAMs) have become highly popular in networking equipment and network processing units. TCAMs are used for highspeed IP lookup and packet classification in switches and routers [1], [2]. Software defined networking (SDN) schemes such as OpenFlow [3] rely on TCAM as the main hardware for their data path. TCAM was also suggested to be used for other computationally intensive tasks such as pattern matching [4], [5], heavy-hitters detection [6], and similarity search in databases [7]. TCAM is an associative memory module. It is composed of an array of ternary words, each consisting of ternary digits, namely: 0, 1, or *. The ‘*’ digits serve as ‘wild cards’ that can be matched with either ‘0’ or ‘1’. Given a query word, TCAM returns the first location in the memory array that matches the query. This process is illustrated in Figure 1.