In my algorithm I need to maintain a set (an unordered list of distinct elements) of expressions supporting two operations:
- Test an expression for membership in the set
- Adding a new expression to the set
Expressions are to be compared using
SameQ. The set can have hundreds of thousands of elements and I want it to work as fast as possible. In most programming languages I would use a hash-table or a balanced tree to implement such a set. Is there any better data structure in Mathematica for this purpose than a plain
List? Is it worth trying to manually implement a better structure?