mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 14:48:21 +00:00
Initial import of svn+ssh:://svn.icir.org/bro/trunk/bro as of r7088
This commit is contained in:
commit
61757ac78b
1383 changed files with 380824 additions and 0 deletions
74
src/IntSet.h
Normal file
74
src/IntSet.h
Normal file
|
@ -0,0 +1,74 @@
|
|||
// $Id: IntSet.h 80 2004-07-14 20:15:50Z jason $
|
||||
|
||||
// A simple but fast data structure for sets of integers.
|
||||
// Only supported operations are insert, remove and membership test.
|
||||
//
|
||||
// It's implemented via a bitmap so the memory usage increases linearly
|
||||
// with max(set).
|
||||
|
||||
#ifndef intset_h
|
||||
#define intset_h
|
||||
|
||||
#include <string.h>
|
||||
|
||||
class IntSet {
|
||||
public:
|
||||
// n is a hint for the value of the largest integer.
|
||||
IntSet(unsigned int n = 1);
|
||||
~IntSet();
|
||||
|
||||
void Insert(unsigned int i);
|
||||
void Remove(unsigned int i);
|
||||
bool Contains(unsigned int i) const;
|
||||
|
||||
void Clear();
|
||||
|
||||
private:
|
||||
void Expand(unsigned int i);
|
||||
|
||||
unsigned int size;
|
||||
unsigned char* set;
|
||||
};
|
||||
|
||||
|
||||
#define bzero(p, size) memset(p, 0, size)
|
||||
|
||||
inline IntSet::IntSet(unsigned int n)
|
||||
{
|
||||
size = n / 8 + 1;
|
||||
set = new unsigned char[size];
|
||||
bzero(set, size);
|
||||
}
|
||||
|
||||
inline IntSet::~IntSet()
|
||||
{
|
||||
delete [] set;
|
||||
}
|
||||
|
||||
inline void IntSet::Insert(unsigned int i)
|
||||
{
|
||||
if ( i / 8 >= size )
|
||||
Expand(i);
|
||||
|
||||
set[i / 8] |= (1 << (i % 8));
|
||||
}
|
||||
|
||||
inline void IntSet::Remove(unsigned int i)
|
||||
{
|
||||
if ( i / 8 >= size )
|
||||
Expand(i);
|
||||
else
|
||||
set[i / 8] &= ~(1 << (i % 8));
|
||||
}
|
||||
|
||||
inline bool IntSet::Contains(unsigned int i) const
|
||||
{
|
||||
return i / 8 < size ? set[i / 8] & (1 << (i % 8)) : false;
|
||||
}
|
||||
|
||||
inline void IntSet::Clear()
|
||||
{
|
||||
bzero(set, size);
|
||||
}
|
||||
|
||||
#endif
|
Loading…
Add table
Add a link
Reference in a new issue