struct treenode_tag { _32 treenode_data; // abitrary structure data }; typedef struct treenode_tag TREENODE; #define MAXTREENODESPERSET 256 DeclareSet( TREENODE );
The important part of the prior code is the last two lines.
#define MAX<your type name>SPERSET <how many>
This defines how many of your structure are kept per set block.
The DeclareSet( type ) declares a typedefed structure called 'struct type##set_tag', 'name##SET', and '*P##name##SET'; in the above case, it would be 'struct TREENODEset_tag', 'TREENODESET', and 'PTREENODESET'.
Then to actually use the set...
// declare a set pointer with one of the magic names. PTREENODESET nodeset = NULL; // get a node from the set. TREENODE *node = GetFromSet( TREENODE, nodeset );
Notice there is no CreateSet, getting a set member will create the set as required. Many operations may expend the set, except for GetUsedSetMember which will only result with members that are definatly in the set. Accesses to the set are all prefixed by the type name the set was created with, 'TREENODE' in this example.
DeleteFromSet( TREENODE, nodeset, node ); node = GetFromSet( TREENODE, nodeset ); { int index = GetMemberIndex( TREENODE, nodeset, node ); }
The accessor macros take care of expanding several parameters that require sizeof structure expansion.