ATLAS Offline Software
Classes | Typedefs | Functions
arraylist.h File Reference

Automatically resizing array. More...

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  _ArrayList
 Definition of an ArrayList. More...
 

Typedefs

typedef void * ArrayListValue
 A value to be stored in an ArrayList. More...
 
typedef struct _ArrayList ArrayList
 An ArrayList structure. More...
 
typedef int(* ArrayListEqualFunc) (ArrayListValue value1, ArrayListValue value2)
 Compare two values in an arraylist to determine if they are equal. More...
 
typedef int(* ArrayListCompareFunc) (ArrayListValue value1, ArrayListValue value2)
 Compare two values in an arraylist. More...
 

Functions

ArrayListarraylist_new (int length)
 Allocate a new ArrayList for use. More...
 
void arraylist_free (ArrayList *arraylist)
 Destroy an ArrayList and free back the memory it uses. More...
 
int arraylist_append (ArrayList *arraylist, ArrayListValue data)
 Append a value to the end of an ArrayList. More...
 
int arraylist_prepend (ArrayList *arraylist, ArrayListValue data)
 Prepend a value to the beginning of an ArrayList. More...
 
void arraylist_remove (ArrayList *arraylist, int index)
 Remove the entry at the specified location in an ArrayList. More...
 
void arraylist_remove_range (ArrayList *arraylist, int index, int length)
 Remove a range of entries at the specified location in an ArrayList. More...
 
int arraylist_insert (ArrayList *arraylist, int index, ArrayListValue data)
 Insert a value at the specified index in an ArrayList. More...
 
int arraylist_index_of (ArrayList *arraylist, ArrayListEqualFunc callback, ArrayListValue data)
 Find the index of a particular value in an ArrayList. More...
 
void arraylist_clear (ArrayList *arraylist)
 Remove all entries from an ArrayList. More...
 
void arraylist_sort (ArrayList *arraylist, ArrayListCompareFunc compare_func)
 Sort the values in an ArrayList. More...
 

Detailed Description

Automatically resizing array.

ArrayLists are arrays of pointers which automatically increase in size.

To create an ArrayList, use arraylist_new. To destroy an ArrayList, use arraylist_free.

To add a value to an ArrayList, use arraylist_prepend, arraylist_append, or arraylist_insert.

To remove a value from an ArrayList, use arraylist_remove or arraylist_remove_range.

Definition in file arraylist.h.

Typedef Documentation

◆ ArrayList

typedef struct _ArrayList ArrayList

An ArrayList structure.

New ArrayLists can be created using the arraylist_new function.

See also
arraylist_new

Definition at line 50 of file arraylist.h.

◆ ArrayListCompareFunc

typedef int(* ArrayListCompareFunc) (ArrayListValue value1, ArrayListValue value2)

Compare two values in an arraylist.

Used by arraylist_sort when sorting values.

Parameters
value1The first value.
value2The second value.
Returns
A negative number if value1 should be sorted before value2, a positive number if value2 should be sorted before value1, zero if the two values are equal.

Definition at line 100 of file arraylist.h.

◆ ArrayListEqualFunc

typedef int(* ArrayListEqualFunc) (ArrayListValue value1, ArrayListValue value2)

Compare two values in an arraylist to determine if they are equal.

Returns
Non-zero if the values are not equal, zero if they are equal.

Definition at line 86 of file arraylist.h.

◆ ArrayListValue

typedef void* ArrayListValue

A value to be stored in an ArrayList.

Definition at line 50 of file arraylist.h.

Function Documentation

◆ arraylist_append()

int arraylist_append ( ArrayList arraylist,
ArrayListValue  data 
)

Append a value to the end of an ArrayList.

Parameters
arraylistThe ArrayList.
dataThe value to append.
Returns
Non-zero if the request was successful, zero if it was not possible to allocate more memory for the new entry.

◆ arraylist_clear()

void arraylist_clear ( ArrayList arraylist)

Remove all entries from an ArrayList.

Parameters
arraylistThe ArrayList.

◆ arraylist_free()

void arraylist_free ( ArrayList arraylist)

Destroy an ArrayList and free back the memory it uses.

Parameters
arraylistThe ArrayList to free.

◆ arraylist_index_of()

int arraylist_index_of ( ArrayList arraylist,
ArrayListEqualFunc  callback,
ArrayListValue  data 
)

Find the index of a particular value in an ArrayList.

Parameters
arraylistThe ArrayList to search.
callbackCallback function to be invoked to compare values in the list with the value to be searched for.
dataThe value to search for.
Returns
The index of the value if found, or -1 if not found.

◆ arraylist_insert()

int arraylist_insert ( ArrayList arraylist,
int  index,
ArrayListValue  data 
)

Insert a value at the specified index in an ArrayList.

The index where the new value can be inserted is limited by the size of the ArrayList.

Parameters
arraylistThe ArrayList.
indexThe index at which to insert the value.
dataThe value.
Returns
Returns zero if unsuccessful, else non-zero if successful (due to an invalid index or if it was impossible to allocate more memory).

◆ arraylist_new()

ArrayList* arraylist_new ( int  length)

Allocate a new ArrayList for use.

Parameters
lengthHint to the initialise function as to the amount of memory to allocate initially to the ArrayList.
Returns
A new arraylist, or NULL if it was not possible to allocate the memory.
See also
arraylist_free

◆ arraylist_prepend()

int arraylist_prepend ( ArrayList arraylist,
ArrayListValue  data 
)

Prepend a value to the beginning of an ArrayList.

Parameters
arraylistThe ArrayList.
dataThe value to prepend.
Returns
Non-zero if the request was successful, zero if it was not possible to allocate more memory for the new entry.

◆ arraylist_remove()

void arraylist_remove ( ArrayList arraylist,
int  index 
)

Remove the entry at the specified location in an ArrayList.

Parameters
arraylistThe ArrayList.
indexThe index of the entry to remove.

◆ arraylist_remove_range()

void arraylist_remove_range ( ArrayList arraylist,
int  index,
int  length 
)

Remove a range of entries at the specified location in an ArrayList.

Parameters
arraylistThe ArrayList.
indexThe index of the start of the range to remove.
lengthThe length of the range to remove.

◆ arraylist_sort()

void arraylist_sort ( ArrayList arraylist,
ArrayListCompareFunc  compare_func 
)

Sort the values in an ArrayList.

Parameters
arraylistThe ArrayList.
compare_funcFunction used to compare values in sorting.