coan 4.2.4
|
#include "ptr_set.h"
#include "memory.h"
#include "swiss_army.h"
#include <string.h>
#include <assert.h>
#include <stddef.h>
Go to the source code of this file.
This file implements the Pointer-Set component
Definition in file ptr_set.c.
void ptr_set_assign | ( | ptr_set_h | dest, |
ptr_set_const_h | src | ||
) |
Assign one pointer set to another.
dest | The pointer set to be assigned |
src | The pointer set to be assigned to dest. |
Definition at line 165 of file ptr_set.c.
References ptr_set_copy(), ptr_set_dispose(), and ptr_set_swap().
Referenced by configured_symbols_rewind().
void** ptr_set_begin | ( | ptr_set_const_h | ps | ) |
Get a pointer to the first pointer in a pointer set. Returns NULL if the pointer set is empty.
Definition at line 290 of file ptr_set.c.
References ptr_vector_begin().
Referenced by ptr_set_begin_const().
void const** ptr_set_begin_const | ( | ptr_set_const_h | ps | ) |
Const variant of ptr_set_begin()
Definition at line 304 of file ptr_set.c.
References ptr_set_begin().
Referenced by configured_symbol_find().
cloner_t ptr_set_cloner | ( | ptr_set_const_h | ps | ) |
Get the cloning function from pointer set
Definition at line 203 of file ptr_set.c.
References ptr_vector_cloner().
comparator_t ptr_set_comparator | ( | ptr_set_const_h | ps | ) |
ptr_set_h ptr_set_copy | ( | ptr_set_const_h | src | ) |
Construct a copy of a pointer set.
src | The pointer set to copy |
Definition at line 145 of file ptr_set.c.
References allocate(), and ptr_set_copy_init().
Referenced by ptr_set_assign().
size_t ptr_set_count | ( | ptr_set_const_h | ps | ) |
Get the number of elements in a pointer set
Definition at line 209 of file ptr_set.c.
References ptr_vector_count().
Referenced by parse_command_args().
Delete a pointer from a pointer set.
ps | The pointer set to be modified. |
loc | The position in the set at which to remove an element. |
If loc lies within ps then the element at pos is removed. Otherwise nothing is done.
Definition at line 283 of file ptr_set.c.
References ptr_vector_delete(), and ptr_set::pv.
void ptr_set_dispose | ( | ptr_set_h | ps | ) |
Dispose of a pointer set.
ps | The pointer set to be destroyed. |
The set's dtor member is called on each element and then remaining memory controlled by the set is released.
The function is a no-op if ps is NULL.
Definition at line 136 of file ptr_set.c.
References ptr_vector_dispose(), and ptr_set::pv.
Referenced by ptr_set_assign().
dtor_t ptr_set_dtor | ( | ptr_set_const_h | ps | ) |
Get the destructor function a pointer set
Definition at line 197 of file ptr_set.c.
References ptr_vector_dtor().
void** ptr_set_end | ( | ptr_set_const_h | ps | ) |
Get the pointer to the first pointer beyond the elements in a pointer set. Returns NULL if the pointer set is empty.
Definition at line 297 of file ptr_set.c.
References ptr_vector_end().
Referenced by ptr_set_end_const().
void const** ptr_set_end_const | ( | ptr_set_const_h | ps | ) |
Const variant of ptr_set_end()
Definition at line 310 of file ptr_set.c.
References ptr_set_end().
Referenced by configured_symbol_find().
bool ptr_set_equal | ( | ptr_set_const_h | lhs, |
ptr_set_const_h | rhs | ||
) |
Say whether two pointer sets are equal.
lhs | The first pointer set to compare. |
rhs | The second pointer set to compare. |
Definition at line 175 of file ptr_set.c.
References eq(), and ptr_vector_equal().
Insert an object into a pointer set.
ps | The pointer set in which the object is to be inserted. |
obj | Address of the object to be inserted, |
Definition at line 236 of file ptr_set.c.
References ptr_set::cached_pos, ptr_set::compare, NOWHERE, ptr_vector_append(), ptr_vector_at(), ptr_vector_count(), ptr_vector_insert(), ptr_vector_search(), ptr_set::pv, and SOMEWHERE.
Referenced by configured_symbol_add(), directive_text_add(), hash_include_add(), and unconfigured_symbol_tally().
ptr_set_h ptr_set_new | ( | comparator_t | compare, |
dtor_t | dtor, | ||
cloner_t | cloner | ||
) |
Create new pointer set.
compare | The key comparison function for this pointer set, or NULL. If NULL then elements are compared by strcmp() |
dtor | The destructor to be applied to set elements when the set is destroyed, or NULL. If NULL then free() is assumed. |
cloner | The cloning function for cloning elements of this set, or NULL. If NULL then clone(ptr,0) is assumed. |
Definition at line 128 of file ptr_set.c.
References allocate(), and ptr_set_init().
Referenced by directive_text_lookup().
Search for a key value in a pointer set.
ps | The pointer set to be searched. |
key | Start of the key value to be searched for. |
keylen | If postive this is the length of the key value to be searched for. If 0 or negative then key is in fact the address of an object that is to be searched for by key. |
If key is not found then ps caches the position at which this key would sort in ps. If the next operation on ps is to insert an obj that matches key then insertion can be highly optimised by localising the second search of the set to the neighbours of the cached position. If this optimisation fails because the object to be inserted next does not match the cached key then that object is inserted the long way.
The pointer returned by this function is invalidated by any subsequent non-const operation on ps.
If the return value is used to modify the key of the object it addresses then ps is corrupted.
Definition at line 215 of file ptr_set.c.
References ptr_set::cached_pos, ptr_set::compare, NOWHERE, ptr_vector_at(), ptr_vector_search(), and ptr_set::pv.
Referenced by configured_symbol_match_const(), directive_text_lookup(), hash_include_lookup(), ptr_set_search_const(), and unconfigured_symbol_tally().
void const* ptr_set_search_const | ( | ptr_set_const_h | ps, |
char const * | key, | ||
locator_t | keylen | ||
) |
Const variant of ptr_set_search()
Definition at line 229 of file ptr_set.c.
References ptr_set_search().
Exchange two pointer sets
Definition at line 155 of file ptr_set.c.
References ptr_set::cached_pos, ptr_set::compare, PODSWAP, ptr_vector_swap(), and ptr_set::pv.
Referenced by ptr_set_assign().