dynamiC  0.1
Functions
DynamicSet

Extension of type LIST to handle and implement SET. More...

Functions

trilean dyn_set_set_len (dyn_c *set, const dyn_ushort len)
 Initialize dynamic element as empty set with maximal length. More...
 
trilean dyn_set_insert (dyn_c *set, dyn_c *element)
 Insert new element into set, if and only if it is not included yet. More...
 

Detailed Description

Extension of type LIST to handle and implement SET.

Function Documentation

◆ dyn_set_insert()

trilean dyn_set_insert ( dyn_c set,
dyn_c element 
)

Insert new element into set, if and only if it is not included yet.

Before a new element is added, it is checked, whether it is already included or not.

Parameters
[in,out]sethas to be of type SET
[in]elementto be added
Return values
DYN_TRUEif memory for the SET could be allocated
DYN_FALSEotherwise

Definition at line 48 of file dynamic_set.c.

49 {
50  dyn_c rslt;
51  DYN_INIT(&rslt);
52  dyn_set_ref(&rslt, element);
53 
54  if (dyn_op_in(&rslt, set)) {
55  if (!dyn_get_bool(&rslt)) {
56  return dyn_list_push(set, element) ? DYN_TRUE : DYN_FALSE;
57  }
58  }
59 
60  return DYN_TRUE;
61 }
represents boolean false
Definition: dynamic_types.h:23
represents boolean true
Definition: dynamic_types.h:24
trilean dyn_op_in(dyn_c *element, dyn_c *container)
Check if dyn2 is element of dyn1.
Definition: dynamic_op.c:949
#define DYN_INIT(dyn)
Mandatory initialization for dynamic elements (NONE)
Definition: dynamic.h:38
trilean dyn_get_bool(const dyn_c *dyn)
Return boolean value of an dynamic element.
Definition: dynamic.c:241
dyn_c * dyn_list_push(dyn_c *list, const dyn_c *element)
Push new element to the end of a list.
Definition: dynamic_list.c:124
void dyn_set_ref(dyn_c *ref, dyn_c *orig)
Set dynamic element as reference to another dynamic element.
Definition: dynamic.c:149
Basic container for dynamic data types.
Definition: dynamic_types.h:98

◆ dyn_set_set_len()

trilean dyn_set_set_len ( dyn_c dyn,
const dyn_ushort  len 
)

Initialize dynamic element as empty set with maximal length.

Generate a set as a list with a maximal available number of preallocated elemens, and change the type of the list to SET. The returned set is empty.

Parameters
[in,out]dynelement to be imp input has to be of type LIST
[in]lenof preallocated elements
Return values
DYN_TRUEif memory for the SET could be allocated
DYN_FALSEotherwise

Definition at line 29 of file dynamic_set.c.

30 {
31  if (dyn_set_list_len(dyn, len)) {
32  dyn->type = SET;
33  return DYN_TRUE;
34  }
35  return DYN_FALSE;
36 }
represents boolean false
Definition: dynamic_types.h:23
represents boolean true
Definition: dynamic_types.h:24
set of type dyn_list
Definition: dynamic_types.h:68
char type
type definition
trilean dyn_set_list_len(dyn_c *dyn, dyn_ushort len)
Set dynamic element to list with maximal length.
Definition: dynamic_list.c:37