tor  0.4.1.0-alpha-dev
Macros | Functions
smartlist_core.c File Reference
#include "lib/err/torerr.h"
#include "lib/malloc/malloc.h"
#include "lib/smartlist_core/smartlist_core.h"
#include <stdlib.h>
#include <string.h>

Go to the source code of this file.

Macros

#define SMARTLIST_DEFAULT_CAPACITY   16
 
#define MAX_CAPACITY   (int)((SIZE_MAX / (sizeof(void*))))
 

Functions

 MOCK_IMPL (smartlist_t *, smartlist_new,(void))
 
 MOCK_IMPL (void, smartlist_free_,(smartlist_t *sl))
 
void smartlist_clear (smartlist_t *sl)
 
static void smartlist_ensure_capacity (smartlist_t *sl, size_t size)
 
void smartlist_add (smartlist_t *sl, void *element)
 
void smartlist_add_all (smartlist_t *s1, const smartlist_t *s2)
 
void smartlist_add_strdup (struct smartlist_t *sl, const char *string)
 
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)
 
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

Implements the core functionality of a smartlist (a resizeable dynamic array). For more functionality and helper functions, see the container library.

Definition in file smartlist_core.c.

Macro Definition Documentation

◆ SMARTLIST_DEFAULT_CAPACITY

#define SMARTLIST_DEFAULT_CAPACITY   16

All newly allocated smartlists have this capacity.

Definition at line 21 of file smartlist_core.c.

Function Documentation

◆ MOCK_IMPL() [1/2]

MOCK_IMPL ( smartlist_t ,
smartlist_new  ,
(void)   
)

Allocate and return an empty smartlist.

Definition at line 25 of file smartlist_core.c.

◆ MOCK_IMPL() [2/2]

MOCK_IMPL ( void  ,
smartlist_free_  ,
(smartlist_t *sl)   
)

Deallocate a smartlist. Does not release storage associated with the list's elements.

Definition at line 38 of file smartlist_core.c.

References smartlist_t::list, and tor_free.

◆ 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 188 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 202 of file smartlist_core.c.

Referenced by smartlist_uniq().

◆ smartlist_ensure_capacity()

static void smartlist_ensure_capacity ( smartlist_t sl,
size_t  size 
)
inlinestatic

Make sure that sl can hold at least size entries.

Definition at line 62 of file smartlist_core.c.

Referenced by smartlist_add().

◆ 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 218 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 161 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 127 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 143 of file smartlist_core.c.

References smartlist_t::list.

Referenced by remove_guard_from_confirmed_and_primary_lists().