mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2025-05-30 08:20:40 +00:00
Add a function to pre-allocate space for a large set.
When the maximum set size is large but constant, and members will be added one at a time, growing the set dynamically is not very efficient.
This commit is contained in:
parent
5950803462
commit
eb2828e11c
2 changed files with 24 additions and 0 deletions
|
@ -93,6 +93,19 @@ void set_del_iter (set_iter_t *set_iter);
|
||||||
*/
|
*/
|
||||||
set_t *set_new (void);
|
set_t *set_new (void);
|
||||||
|
|
||||||
|
/** Create a new set with space pre-allocated for the specified set size.
|
||||||
|
|
||||||
|
Although sets automatically grow to accommodate new members as necessary,
|
||||||
|
sometimes the maximum set size is known in advance and it can be more
|
||||||
|
efficient to grow the set in advance.
|
||||||
|
|
||||||
|
The set is initialized to be the empty set.
|
||||||
|
|
||||||
|
\param size The number of elements for which space is to be allocated.
|
||||||
|
\return The newly created, empty set.
|
||||||
|
*/
|
||||||
|
set_t *set_new_size (int size);
|
||||||
|
|
||||||
/** Delete a set that is no longer needed.
|
/** Delete a set that is no longer needed.
|
||||||
|
|
||||||
\param set The set to be deleted.
|
\param set The set to be deleted.
|
||||||
|
|
|
@ -107,6 +107,17 @@ set_expand (set_t *set, unsigned x)
|
||||||
free (map);
|
free (map);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
set_t *
|
||||||
|
set_new_size (int size)
|
||||||
|
{
|
||||||
|
set_t *set;
|
||||||
|
|
||||||
|
set = set_new ();
|
||||||
|
set_expand (set, size);
|
||||||
|
|
||||||
|
return set;
|
||||||
|
}
|
||||||
|
|
||||||
static inline void
|
static inline void
|
||||||
_set_add (set_t *set, unsigned x)
|
_set_add (set_t *set, unsigned x)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue