**Index**

# set

Sets of task identifiers are used by a number of components of the multitasking library, e.g. the set of waiting tasks and the set of active receivers associated with a channel.

**Data Structure**

Sets are stored in a structure with only one field of type unsigned integer used to represent the members of the set. Each bit in the

*members*field represents the presence or absence of a task in the set, e,g, if bit 3 is set, the task with identifier 3 is a member of the set, and if bit 3 is cleared then the task with identifier 3 is not a member of the set.

Arduino variables of type integer contain 16 bits. This limits the number of tasks that can be stored in a set to 16 with identifiers to from 0 to 15.

struct set

{

unsigned int members;

};

{

unsigned int members;

};

**Functions**

Sets support the following functions. For consistency, all of the set functions take pointers to structures of type

*set*so that the

*members*field can be updated when required.

**init_set**

void init_set(set* s);

This function makes a set empty by removing all task identifiers from it.

**insert**

void insert(set* s, byte id);

**remove**

This function inserts the identifier of a task into the set. If the task is already a member the set, this causes no change.

byte remove(set* s, byte id);

This function removes the identifier of a task from the set. If the task is not a member of the set, this causes no change.

**in_set**

bool in_set(set* s, byte id);

This function returns

*true*if the supplied identifier is a member of the set. Otherwise it returns

*false*.

**in_set**

bool in_set(set* s1, set* s2);

This function returns

*true*if all the members of the set

*s2*are also members of the set

*s1*, i.e. s2 is a proper subset of s1. It returns

*false*otherwise.

**empty_set**

bool empty_set(set* s);

This function returns

*true*if the set has no members, and

*false*otherwise.