Data Structures | Macros | Typedefs | Functions
smartlist_core.h File Reference
#include <stddef.h>
#include "lib/cc/compat_compiler.h"
#include "lib/cc/torint.h"
#include "lib/testsupport/testsupport.h"

Go to the source code of this file.

Data Structures

struct  smartlist_t


#define smartlist_free(sl)   FREE_AND_NULL(smartlist_t, smartlist_free_, (sl))
#define smartlist_len(sl)   ((sl)->num_used)
#define smartlist_get(sl, idx)   ((sl)->list[idx])
#define smartlist_set(sl, idx, val)   ((sl)->list[idx] = (val))


typedef struct smartlist_t smartlist_t


 MOCK_DECL (smartlist_t *, smartlist_new,(void))
 MOCK_DECL (void, smartlist_free_,(smartlist_t *sl))
void smartlist_clear (smartlist_t *sl)
void smartlist_add (smartlist_t *sl, void *element)
void smartlist_add_all (smartlist_t *sl, const smartlist_t *s2)
void smartlist_add_strdup (struct smartlist_t *sl, const char *string)
void smartlist_grow (smartlist_t *sl, size_t new_size)
void smartlist_remove (smartlist_t *sl, const void *element)
void smartlist_remove_keeporder (smartlist_t *sl, const void *element)
void * smartlist_pop_last (smartlist_t *sl)
int smartlist_contains (const smartlist_t *sl, const void *element)
static void smartlist_swap (smartlist_t *sl, int idx1, int idx2)
void smartlist_del (smartlist_t *sl, int idx)
void smartlist_del_keeporder (smartlist_t *sl, int idx)
void smartlist_insert (smartlist_t *sl, int idx, void *val)

Detailed Description

Top-level declarations for the smartlist_t dynamic array type.

Definition in file smartlist_core.h.

Typedef Documentation

◆ smartlist_t

typedef struct smartlist_t smartlist_t

A resizeable list of pointers, with associated helpful functionality.

The members of this struct are exposed only so that macros and inlines can use them; all access to smartlist internals should go through the functions and macros defined here.

Function Documentation

◆ smartlist_add()

void smartlist_add ( smartlist_t sl,
void *  element 

◆ smartlist_add_all()

void smartlist_add_all ( smartlist_t s1,
const smartlist_t s2 

◆ smartlist_add_strdup()

void smartlist_add_strdup ( struct smartlist_t sl,
const char *  string 

◆ smartlist_clear()

void smartlist_clear ( smartlist_t sl)

◆ smartlist_contains()

int smartlist_contains ( const smartlist_t sl,
const void *  element 

◆ smartlist_del()

void smartlist_del ( smartlist_t sl,
int  idx 

Remove the idxth element of sl; if idx is not the last element, swap the last element of sl into the idxth space.

Definition at line 214 of file smartlist_core.c.

Referenced by circuit_close_all_marked(), and routerlist_insert().

◆ smartlist_del_keeporder()

void smartlist_del_keeporder ( smartlist_t sl,
int  idx 

Remove the idxth element of sl; if idx is not the last element, moving all subsequent elements back one space. Return the old value of the idxth element.

Definition at line 228 of file smartlist_core.c.

Referenced by smartlist_uniq().

◆ smartlist_grow()

void smartlist_grow ( smartlist_t sl,
size_t  new_size 

Expand sl so that its length is at least new_size, filling in previously unused entries with NULL>

Do nothing if sl already had at least new_size elements.

Definition at line 97 of file smartlist_core.c.

References smartlist_t::list, and smartlist_ensure_capacity().

Referenced by dcfg_add_recv(), and dcfg_msg_set_chan().

◆ smartlist_insert()

void smartlist_insert ( smartlist_t sl,
int  idx,
void *  val 

Insert the value val as the new idxth element of sl, moving all items previously at idx or later forward one space.

Definition at line 244 of file smartlist_core.c.

◆ smartlist_pop_last()

void* smartlist_pop_last ( smartlist_t sl)

If sl is nonempty, remove and return the final element. Otherwise, return NULL.

Definition at line 187 of file smartlist_core.c.

◆ smartlist_remove()

void smartlist_remove ( smartlist_t sl,
const void *  element 

Remove all elements E from sl such that E==element. Preserve the order of any elements before E, but elements after E can be rearranged.

Definition at line 151 of file smartlist_core.c.

References smartlist_t::list.

Referenced by circuit_about_to_free(), connection_stop_reading_from_linked_conn(), connection_unlink(), and smartlist_subtract().

◆ smartlist_remove_keeporder()

void smartlist_remove_keeporder ( smartlist_t sl,
const void *  element 

As smartlist_remove, but do not change the order of any elements not removed

Definition at line 167 of file smartlist_core.c.

References smartlist_t::list.

Referenced by remove_guard_from_confirmed_and_primary_lists().

◆ smartlist_swap()

static void smartlist_swap ( smartlist_t sl,
int  idx1,
int  idx2 

Exchange the elements at indices idx1 and idx2 of the smartlist sl.

Definition at line 88 of file smartlist_core.h.