Integer Sets
The data type int_set can be used to store a subset of a fixed interval
of ints.
Example
The following program shows how to use Integer Sets. It generates an int_set
IS for ints between 1 and 1000 and inserts 100 ints into IS .
Then it searches for entries 37 and 168 in IS .
#include <LEDA/core/int_set.h>
int main()
{
leda::int_set IS(1,1000);
int i;
for (i=1; i<=100; i++) IS.insert(2*i);
if (IS.member(37)) std::cout << "37 is stored in S\n";
else std::cout << "37 is not an element of S\n";
if (IS.member(168)) std::cout << "168 is stored in S\n";
else std::cout << "168 is not an element of S\n";
return 0;
}
Strengths
-
insert(), delete(), member(), empty(), size() need only constant
time
- intersection, union, and complement need time proportional to the
size of the interval.
- all operations are very fast (data type uses parallelism at word
level)
- data type is very space efficient
Disadvantages
Tips
|
See also:
Dynamic Integer Sets
Sets
Linear Lists
One Dimensional Arrays
Manual
Page Integer Sets
|