Salad  1.0.15
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Groups Pages
Data Structures | Macros | Typedefs | Functions
Sld_vector

Data Structures

struct  sld_vector
 

Macros

#define INITIAL_CAPACITY   16
 
#define RESIZE_FACTOR   2
 

Typedefs

typedef struct sld_vector sld_vector
 

Functions

SLD_SSINT sld_vector_init (sld_vector *vector)
 Initializes a sld_vector. More...
 
SLD_SSINT sld_vector_init_size (sld_vector *vector, int size)
 Initializes a sld_vector with the specified size. More...
 
SLD_UINT sld_vector_objects (sld_vector *vector)
 Returns the number of objects contained within a sld_vector. More...
 
SLD_UINT sld_vector_size (sld_vector *vector)
 Returns the capacity of a sld_vector. More...
 
SLD_SSINT sld_vector_resize (sld_vector *vector, int new_size)
 Resizes a sld_vector to the specified size. More...
 
SLD_SSINT sld_vector_add (sld_vector *vector, void *object)
 Adds an object to a sld_vector. More...
 
void * sld_vector_get (sld_vector *vector, int index)
 Returns an object from an sld_vector at index. More...
 
void sld_vector_set (sld_vector *vector, int index, void *object)
 Sets the data residing at the specified index in a sld_vector. More...
 
void * sld_vector_pop (sld_vector *vector)
 Returns and removes the last object in a sld_vector. More...
 
void sld_vector_delete (sld_vector *vector, SLD_UINT index)
 Removes an object from a sld_vector at the specified index. More...
 
void sld_vector_free (sld_vector *vector)
 Frees any memory allocated for an initialized sld_vector. More...
 

Detailed Description

This module contains functions, macros, and structures related to sld_vector objects.

Macro Definition Documentation

#define INITIAL_CAPACITY   16

Default initial capacity for a sld_vector

#define RESIZE_FACTOR   2

Double or halve a sld_vector during a resize operation

Typedef Documentation

typedef struct sld_vector sld_vector

A sld_vector is a resizeable array

Function Documentation

SLD_SSINT sld_vector_add ( sld_vector vector,
void *  object 
)
related

Adds an object to a sld_vector.

Parameters
vectoran initialized sld_vector
objectan arbitrary object
Returns
Success or failure
sld_vector_add(&vector, "foo");
Examples:
vector.c.
void sld_vector_delete ( sld_vector vector,
SLD_UINT  index 
)
related

Removes an object from a sld_vector at the specified index.

Parameters
vectoran initialized sld_vector
indexan index where an object resides within the sld_vector
sld_vector_delete(&vector, 9);
void sld_vector_free ( sld_vector vector)
related

Frees any memory allocated for an initialized sld_vector.

Parameters
vectoran initialized sld_vector
sld_vector_free(&vector);
Examples:
vector.c.
void * sld_vector_get ( sld_vector vector,
int  index 
)
related

Returns an object from an sld_vector at index.

Parameters
vectoran initialized sld_vector
indexan index where an object resides within the sld_vector
Returns
The object residing at the specified index
puts((char *)sld_vector_get(&vector, 13));
Examples:
vector.c.
SLD_SSINT sld_vector_init ( sld_vector vector)
related

Initializes a sld_vector.

Parameters
vectoran uninitialized sld_vector
Returns
Success or failure
sld_vector vector;
sld_vector_init(&vector);
Examples:
vector.c.
SLD_SSINT sld_vector_init_size ( sld_vector vector,
int  size 
)
related

Initializes a sld_vector with the specified size.

Parameters
vectoran uninitialized sld_vector
sizean initial size
Returns
Success or failure
sld_vector vector;
sld_vector_init_size(&vector, 32);
SLD_UINT sld_vector_objects ( sld_vector vector)
related

Returns the number of objects contained within a sld_vector.

Parameters
vectoran initialized sld_vector
Returns
The number of objects contained within the passed sld_vector
if(sld_vector_objects(&vector) < sld_vector_size(&vector))
puts("We can shove more into the vector!");
Examples:
vector.c.
void * sld_vector_pop ( sld_vector vector)
related

Returns and removes the last object in a sld_vector.

Parameters
vectoran initialized sld_vector
Returns
The last object in the passed sld_vector
puts((char *)sld_vector_pop(&vector));
Examples:
vector.c.
SLD_SSINT sld_vector_resize ( sld_vector vector,
int  new_size 
)
related

Resizes a sld_vector to the specified size.

Parameters
vectoran initialized sld_vector
new_sizethe new size of the sld_vector
Returns
Success or failure
sld_vector_resize(&vector, 64);
void sld_vector_set ( sld_vector vector,
int  index,
void *  object 
)
related

Sets the data residing at the specified index in a sld_vector.

Parameters
vectoran initialized sld_vector
indexan index where an object may reside within the sld_vector
objectan arbitrary object
sld_vector_set(&vector, 21, "foo");
SLD_UINT sld_vector_size ( sld_vector vector)
related

Returns the capacity of a sld_vector.

Parameters
vectoran initialized sld_vector
Returns
The capacity of the passed sld_vector
if(sld_vector_size(&vector) == sld_vector_objects(&vector))
puts("We need to resize the vector!");