[erlang-questions] working with sets

Richard Carlsson richardc@REDACTED
Fri Jan 4 12:44:35 CET 2008

Vance Shipley wrote:
> Can one of you CS wizzes point me at the best way to
> maintain a set of sets where all elements of all sets
> must be unique?  I don't need a really big data set
> but rolling my own with the list module feels wrong.
> For example {{1,2,3},{4,5,6},{7,8,9}} is a valid set.
> Trying to enter {9,10,11} should fail.

If your elements are really integers within a limited range
(or can easily be mapped to/from such integers), the old
set-as-bitmap representation can be a good choice. Since
Erlang has bignums, your bitmaps are simply integers. This
gives you fast intersection tests (A band B).

Writing a sets-like interface to bitmaps (for the operations
that you neeed) is easy, and lets you switch between
implementations later.


More information about the erlang-questions mailing list