My library
Library for common tasks
Functions
arrayList.h File Reference

Functions for working with ArrayList type. More...

#include "types.h"
Include dependency graph for arrayList.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

ArrayList newAL (const spec_t spec)
 Allocate a new ArrayList of specified type. More...
 
ArrayList newALFromAL (const ArrayList list)
 Get a copy of an ArrayList. More...
 
void appendToAL (ArrayList list,...)
 Insert an item at the end of an ArrayList. More...
 
void insertToAL (ArrayList list, unsigned int index,...)
 Insert an item at a specified position of an ArrayList. More...
 
void setALItem (ArrayList list, unsigned int index,...)
 Set value of an item of an ArrayList. More...
 
void mergeAL (ArrayList list1, const ArrayList list2)
 Merge two ArrayList. More...
 
void sliceAL (ArrayList list, unsigned int begin, unsigned int end)
 Slice an ArrayList. More...
 
void printAL (const spec_t spec, const ArrayList list)
 Print contents from an ArrayList. More...
 
void removeFromAL (ArrayList list, unsigned int index)
 Remove an item from an ArrayList. More...
 
void getFromAL (const ArrayList list, unsigned int index, void *dest)
 Get an item from an ArrayList. More...
 
void deleteAL (ArrayList list,...)
 Delete an ArrayList. More...
 
byte areALEqual (const ArrayList list1, const ArrayList list2,...)
 Compare two ArrayList. More...
 
void reverseAL (ArrayList list)
 Reverse an ArrayList. More...
 
void bubbleSortAL (ArrayList list,...)
 Bubble sort for ArrayList. More...
 
void quickSortAL (ArrayList list,...)
 Quicksort for ArrayList. More...
 
byte isInAL (ArrayList list,...)
 Detect if an item is inside an ArrayList. More...
 
int linearSearchAL (ArrayList list,...)
 Linear search for ArrayList. More...
 
ArrayList chooseNewALFromArray (const spec_t spec, const void *list, unsigned int size)
 Create an ArrayList from a static array. More...
 
ArrayList newALFromCharArray (const char list[], unsigned int size)
 Create ArrayList from a list of chars. More...
 
ArrayList newALFromByteArray (const char list[], unsigned int size)
 Create ArrayList from a list of bytes. More...
 
ArrayList newALFromIntArray (const int list[], unsigned int size)
 Create ArrayList from a list of ints. More...
 
ArrayList newALFromFloatArray (const float list[], unsigned int size)
 Create ArrayList from a list of floats. More...
 
ArrayList newALFromDoubleArray (const double list[], unsigned int size)
 Create ArrayList from an list of doubles. More...
 
ArrayList newALFromPtrArray (const void *list, unsigned int size)
 Create ArrayList from an list of pointers. More...
 
unsigned int getALLength (const ArrayList list)
 Get the size of an ArrayList. More...
 
byte isALEmpty (ArrayList list)
 Check if ArrayList is empty. More...
 

Detailed Description

Functions for working with ArrayList type.

Author
Pietro Firpo (pietr.nosp@m.o.fi.nosp@m.rpo@p.nosp@m.m.me)

Function Documentation

◆ appendToAL()

void appendToAL ( ArrayList  list,
  ... 
)

Insert an item at the end of an ArrayList.

Parameters
listThe ArrayList you want to append an item to
...The item you want to append to list
Note
Even though appending more than one item for single call does not throw a compiler nor runtime error, only appending one item is supported. Other items are ignored and are not appended to list. If you don't specify any item to be appended, still no errors occur but the content of your ArrayList can be messed up

◆ areALEqual()

byte areALEqual ( const ArrayList  list1,
const ArrayList  list2,
  ... 
)

Compare two ArrayList.

Parameters
list1The first ArrayList you want to compare
list2The second ArrayList you want to compare
...The comparison function needed to compare items inside given lists. This parameter is necessary only for pointer ArrayList type and is ignored otherwise. Must be a function that takes two pointers as argument and returns a positive int if the item pointed by the first argument is greater than the item pointed by the second argument, a negative int if the item pointed by the first argument is is smaller than the item pointed by second, a zero int if the item pointed by first and second arguments are equal
Note
If comparing two pointer ArrayList type and the comparing function is not given a compiler nor runtime error is given, but the result of the comparison is unpredictable
Returns
The result of the comparison
Return values
TRUElist1 and list2 have equal type, equal length and equal contents
FALSElist1 and list2 do not have equal type, equal length or equal contents

◆ bubbleSortAL()

void bubbleSortAL ( ArrayList  list,
  ... 
)

Bubble sort for ArrayList.

Parameters
listThe ArrayList you want to bubble sort
...The comparison function needed to compare items inside given lists. This parameter is necessary only for pointer ArrayList type and is ignored otherwise. Must be a function that takes two pointers as argument and returns a positive int if the item pointed by the first argument is greater than the item pointed by the second argument, a negative int if the item pointed by the first argument is is smaller than the item pointed by second, a zero int if the item pointed by first and second arguments are equal
Note
If sorting an ArrayList type and the comparing function is not passed a compiler error is not given, but the ArrayList will be messed up

◆ chooseNewALFromArray()

ArrayList chooseNewALFromArray ( const spec_t  spec,
const void *  list,
unsigned int  size 
)

Create an ArrayList from a static array.

Parameters
specThe type specifier of the array passed. Refer to spec_t
listThe list you want to create the ArrayList from
sizeThe number of items in list
Note
When creating an ArrayList from a pointer array the pointers are inserted into the ArrayList, not what they point to
Returns
An ArrayList containing the items in list in the same order

◆ deleteAL()

void deleteAL ( ArrayList  list,
  ... 
)

Delete an ArrayList.

Parameters
listThe ArrayList you want to delete
...The function used to free memory pointed by every pointer of the ArrayList. Must be a function that takes a pointer as argument. Necessary only for pointer ArrayList type, ignored otherwise. When deleting a pointer ArrayList type if no free function is passed no compiler errors are thrown but you may cause severe memory leaks

◆ getALLength()

unsigned int getALLength ( const ArrayList  list)

Get the size of an ArrayList.

Parameters
listThe ArrayList you want to evaluate
Returns
The number of items in list

◆ getFromAL()

void getFromAL ( const ArrayList  list,
unsigned int  index,
void *  dest 
)

Get an item from an ArrayList.

Parameters
listThe ArrayList you want to get an item from
indexThe index of the item you want to get
destThe address of the variable you want to store the item in

◆ insertToAL()

void insertToAL ( ArrayList  list,
unsigned int  index,
  ... 
)

Insert an item at a specified position of an ArrayList.

Parameters
listThe ArrayList you want to insert an item into
indexThe position you want to insert an item at
...The item you want to insert into list
Note
Even though inserting more than one item for single call does not throw a compiler nor runtime error, only inserting one item is supported. Other items are ignored and are not inserted into list. If you don't specify any item to be inserted, still no errors occur but the content of your ArrayList can be messed up

◆ isALEmpty()

byte isALEmpty ( ArrayList  list)

Check if ArrayList is empty.

Parameters
listThe ArrayList to be checked
Return values
TRUElist is empty
FALSElist is not empty

◆ isInAL()

byte isInAL ( ArrayList  list,
  ... 
)

Detect if an item is inside an ArrayList.

Parameters
listThe ArrayList you want search in
...The item you want to search. If searaching in a pointer ArrayList type, after the item you want so search, you must provide the comparison function needed to compare the item you want to search and the items in the ArrayList. Must be a function that takes two pointers as argument and returns a zero int only if the item pointed by first and second arguments are equal
Note
Even though searching more than one item for single call does not throw a compiler nor runtime error, only searching one item is supported. Other items are ignored. If you don't specify any item to be searched, still no errors occur but the return value of the function can be unpredictable. If searching in a pointer ArrayList type and the comparing function is not passed a compiler error is not given either, but the return value of the function can be unpredictable
Return values
TRUEGiven item is contained in list
FALSEGiven item is not contained in list

◆ linearSearchAL()

int linearSearchAL ( ArrayList  list,
  ... 
)

Linear search for ArrayList.

Parameters
listThe ArrayList to be inspected
...The key to be searched. If searaching in a pointer ArrayList type, after the item you want so search, you must provide the comparison function needed to compare the item you want to search and the items in the ArrayList. Must be a function that takes two pointers as argument and returns a zero int only if the item pointed by first and second arguments are equal
Note
Even though passing more than one key does not throw a compiler nor runtime error, only searching one key is supported. Other items are ignored. If you don't specify any item to be searched, still no errors occur but the return value of the function can be unpredictable. If searching in a pointer ArrayList type and the comparing function is not passed a compiler or runtime error is not given either, but the return value of the function can be unpredictable
Returns
The index of the first occurence of the key in the list or the return code of the function
Return values
KEY_NOT_FOUNDThe key was not found

◆ mergeAL()

void mergeAL ( ArrayList  list1,
const ArrayList  list2 
)

Merge two ArrayList.

Parameters
list1The first ArrayList to be merged, where the merged ArrayList is saved
list2The second ArrayList to be merged

◆ newAL()

ArrayList newAL ( const spec_t  spec)

Allocate a new ArrayList of specified type.

Parameters
specType specifier of the ArrayList you want to create
Returns
An empty ArrayList

◆ newALFromAL()

ArrayList newALFromAL ( const ArrayList  list)

Get a copy of an ArrayList.

Parameters
listThe ArrayList you want to copy
Note
When creating an ArrayList from a pointer ArrayList type the pointers in list are inserted into the ArrayList, not what they point to
Returns
A copy of list

◆ newALFromByteArray()

ArrayList newALFromByteArray ( const char  list[],
unsigned int  size 
)

Create ArrayList from a list of bytes.

Alias for newALFromCharArray(). Used to create ArrayList from byte list. Refer to newALFromCharArray()

◆ newALFromCharArray()

ArrayList newALFromCharArray ( const char  list[],
unsigned int  size 
)

Create ArrayList from a list of chars.

Equivalent to chooseNewALFromArray("%c", list, size). Refer to chooseNewALFromArray()

◆ newALFromDoubleArray()

ArrayList newALFromDoubleArray ( const double  list[],
unsigned int  size 
)

Create ArrayList from an list of doubles.

Equivalent to chooseNewALFromArray("%lf", list, size). Refer to chooseNewALFromArray()

◆ newALFromFloatArray()

ArrayList newALFromFloatArray ( const float  list[],
unsigned int  size 
)

Create ArrayList from a list of floats.

Equivalent to chooseNewALFromArray("%f", list, size). Refer to chooseNewALFromArray()

◆ newALFromIntArray()

ArrayList newALFromIntArray ( const int  list[],
unsigned int  size 
)

Create ArrayList from a list of ints.

Equivalent to chooseNewALFromArray("%i", list, size). Refer to chooseNewALFromArray()

◆ newALFromPtrArray()

ArrayList newALFromPtrArray ( const void *  list,
unsigned int  size 
)

Create ArrayList from an list of pointers.

Equivalent to chooseNewALFromArray("%p", list, size). Refer to chooseNewALFromArray()

◆ printAL()

void printAL ( const spec_t  spec,
const ArrayList  list 
)

Print contents from an ArrayList.

Parameters
specThe type and format specifier you want to use to print the single item of the ArrayList. Use the printf() conventions
listThe ArrayList you want to print

◆ quickSortAL()

void quickSortAL ( ArrayList  list,
  ... 
)

Quicksort for ArrayList.

Parameters
listThe ArrayList you want to quicksort
...The comparison function needed to compare items inside given lists. This parameter is necessary only for pointer ArrayList type and is ignored otherwise. Must be a function that takes two pointers as argument and returns a positive int if the item pointed by the first argument is greater than the item pointed by the second argument, a negative int if the item pointed by the first argument is is smaller than the item pointed by second, a zero int if the item pointed by first and second arguments are equal
Note
If sorting a pointer ArrayList type and the comparing function is not passed a compiler error is not given, but the ArrayList will be messed up

◆ removeFromAL()

void removeFromAL ( ArrayList  list,
unsigned int  index 
)

Remove an item from an ArrayList.

Parameters
listThe ArrayList you want to delete an item from
indexThe index of the item you want to delete

◆ reverseAL()

void reverseAL ( ArrayList  list)

Reverse an ArrayList.

Parameters
listThe ArrayList you want to reverse

◆ setALItem()

void setALItem ( ArrayList  list,
unsigned int  index,
  ... 
)

Set value of an item of an ArrayList.

Parameters
listThe ArrayList you want to edit
indexThe index of the item you want to change
...The item you want to set the index-th item of list to
Note
Even though changing more than one item for single call does not throw a compiler nor runtime error, only setting one item is supported. Other items are ignored. If you don't specify any item to be inserted, still no errors occur but the content of your ArrayList can be messed up

◆ sliceAL()

void sliceAL ( ArrayList  list,
unsigned int  begin,
unsigned int  end 
)

Slice an ArrayList.

Parameters
listThe ArrayList you want to slice, where the sliced ArrayList is saved
beginThe index of the beginning of the slice
endThe index of the end of the slice