offbrand
A collection of generic, reference counted datastructures in C for C
 All Classes Files Functions Variables Typedefs Macros Groups
Typedefs | Functions
obdeque.h File Reference

obdeque Public Interface More...

#include "offbrand.h"

Go to the source code of this file.

Typedefs

typedef struct obdeque_struct obdeque
 
typedef struct
obdeque_iterator_struct 
obdeque_iterator
 

Functions

obdequeobdeque_new (void)
 Constructor, creates a new instance of obdeque with no contents. More...
 
obdequeobdeque_copy (const obdeque *to_copy)
 Copy Constructor, creates a new obdeque that contains the same contents as an obdeque instance. More...
 
uint8_t obdeque_is_empty (const obdeque *deque)
 The emptyness state of an obdeque, either empty or non-empty. More...
 
uint64_t obdeque_length (const obdeque *deque)
 Number of elements stored within an obdeque. More...
 
obdeque_iteratorobdeque_head_iterator (const obdeque *deque)
 Constructor for an iterator for an obdeque that is directed at the head of the obdeque. More...
 
obdeque_iteratorobdeque_tail_iterator (const obdeque *deque)
 Constructor for an iterator for an obdeque that is directed at the tail of the obdeque. More...
 
obdeque_iteratorobdeque_copy_iterator (const obdeque_iterator *it)
 Copy Constructor for an obdeque_iterator from another obdeque_iterator. More...
 
uint8_t obdeque_iterate_next (const obdeque *deque, obdeque_iterator *it)
 Advance an obdeque_iterator bound to an obdeque to the next element within the obdeque closer to the tail of the obdeque. More...
 
uint8_t obdeque_iterate_prev (const obdeque *deque, obdeque_iterator *it)
 Advance an obdeque_iterator bound to an obdeque to the previous element within the obdeque closer to the obdeque head. More...
 
void obdeque_add_at_head (obdeque *deque, obj *to_add)
 Add an obj to the head of an obdeque. More...
 
void obdeque_add_at_tail (obdeque *deque, obj *to_add)
 Add an obj to the tail of an obdeque. More...
 
void obdeque_add_at_iterator (obdeque *deque, obdeque_iterator *it, obj *to_add)
 Add an obj to an obdeque at position before the element specified by an obdeque_iterator. More...
 
obdequeobdeque_join (const obdeque *d1, const obdeque *d2)
 creates a new obdeque that contains the ordered contents of two obdeques More...
 
uint8_t obdeque_find_obj (const obdeque *deque, const obj *to_find)
 Searches an obdeque for an obj. More...
 
void obdeque_sort (obdeque *deque, int8_t order)
 Sorts an obdeque from least-to-greatest or greatest-to-least using the standard compare function. More...
 
void obdeque_sort_with_funct (obdeque *deque, int8_t order, ob_compare_fptr funct)
 Sorts an obdeque from least-to-greatest or greatest-to-least using a specified comparision function. More...
 
objobdeque_obj_at_head (const obdeque *deque)
 Peek at the obj stored at the head of an obdeque. More...
 
objobdeque_obj_at_tail (const obdeque *deque)
 Peek at the obj stored at the tail of an obdeque. More...
 
objobdeque_obj_at_iterator (const obdeque *deque, const obdeque_iterator *it)
 Peek at the obj stored within a obdeque stored at the position denoted by an obdeque_iterator bound to that obdeque. More...
 
void obdeque_remove_head (obdeque *deque)
 Remove the obj stored at the head of an obdeque, shrinking the obdeque by one element. More...
 
void obdeque_remove_tail (obdeque *deque)
 Remove the obj stored at the tail of an obdeque, shrinking the obdeque by one element. More...
 
void obdeque_remove_at_iterator (obdeque *deque, obdeque_iterator *it)
 Remove the obj stored within an obdeque at the position denoted by the obdeque_iterator bound to that obdeque, shrinking the obdeque by one element. More...
 
void obdeque_clear (obdeque *deque)
 removes all obj's from the Deque, leaving the Deque empty More...
 

Detailed Description

obdeque Public Interface

Author

Typedef Documentation

typedef struct obdeque_struct obdeque

Class type declaration

Class specific iterator type declaration.

Function Documentation

void obdeque_add_at_head ( obdeque deque,
obj to_add 
)

Add an obj to the head of an obdeque.

Parameters
dequeAn instance of obdeque
to_addAny instance of an Offbrand compatible class to add to deque
void obdeque_add_at_iterator ( obdeque deque,
obdeque_iterator it,
obj to_add 
)

Add an obj to an obdeque at position before the element specified by an obdeque_iterator.

Parameters
dequeAn instance of obdeque
itAn instance of obdeque_iterator bound to deque
to_addAny instance of an Offbrand compatible class to add to deque
void obdeque_add_at_tail ( obdeque deque,
obj to_add 
)

Add an obj to the tail of an obdeque.

Parameters
dequeAn instance of obdeque
to_addAny instance of an Offbrand compatible class to add to deque
void obdeque_clear ( obdeque deque)

removes all obj's from the Deque, leaving the Deque empty

Parameters
dequeAn instance of obdeque
obdeque* obdeque_copy ( const obdeque to_copy)

Copy Constructor, creates a new obdeque that contains the same contents as an obdeque instance.

Parameters
to_copyAn instance of obdeque to copy
Returns
Pointer to a newly created and initialized instance of obdeque
obdeque_iterator* obdeque_copy_iterator ( const obdeque_iterator it)

Copy Constructor for an obdeque_iterator from another obdeque_iterator.

Parameters
itAn instance of obdeque_iterator
Returns
An obdeque_iterator instance bound to the same obdeque as the provided obdeque_iterator and directect at the same location within that obdeque
Warning
The obdeque_iterator created by this method MUST be released by the user, else a memory leak will occur
uint8_t obdeque_find_obj ( const obdeque deque,
const obj to_find 
)

Searches an obdeque for an obj.

Parameters
dequeAn instance of obdeque
to_findAn instance of any Offbrand compatible class to search for within the deque
Return values
0to_find not found within deque
1to_find found within the deque
obdeque_iterator* obdeque_head_iterator ( const obdeque deque)

Constructor for an iterator for an obdeque that is directed at the head of the obdeque.

Parameters
dequeAn instance of obdeque
Return values
NULLThe obdeque provided is empty and cannot be iterated
non-NULLAn obdeque_iterator instance bound to the provided instance of obdeque and directed at the head of that obdeque
Warning
The obdeque_iterator created by this method MUST be released by the user, else a memory leak will occur
uint8_t obdeque_is_empty ( const obdeque deque)

The emptyness state of an obdeque, either empty or non-empty.

Parameters
dequeAn instance of obdeque
Return values
0The deque is empty
non-zeroThe deque contains elements
uint8_t obdeque_iterate_next ( const obdeque deque,
obdeque_iterator it 
)

Advance an obdeque_iterator bound to an obdeque to the next element within the obdeque closer to the tail of the obdeque.

Parameters
dequeAn instance of obdeque
itAn intstance of obdeque_iterator that is bound to deque
Return values
non-zeroAdvancement was successful.
0Advancement failed because no more elements exist in the obdeque closer to the deque tail
uint8_t obdeque_iterate_prev ( const obdeque deque,
obdeque_iterator it 
)

Advance an obdeque_iterator bound to an obdeque to the previous element within the obdeque closer to the obdeque head.

Parameters
dequeAn instance of obdeque
itAn intstance of obdeque_iterator that is bound to deque
Return values
non-zeroAdvancement was successful.
0Advancement failed because no more elements exist in the obdeque closer to the deque head
obdeque* obdeque_join ( const obdeque d1,
const obdeque d2 
)

creates a new obdeque that contains the ordered contents of two obdeques

Parameters
d1First obdeque to copy into the resultant obdeque
d2Second obdeque to copy onto the end of the resultant obdeque
Returns
An obdeque instance that contains the contents of d1 followed by d2
uint64_t obdeque_length ( const obdeque deque)

Number of elements stored within an obdeque.

Parameters
dequeAn instance of obdeque
Returns
An integer corresponding the the number of objects in the deque
obdeque* obdeque_new ( void  )

Constructor, creates a new instance of obdeque with no contents.

Returns
Pointer to a newly created and initialized instance of obdeque
obj* obdeque_obj_at_head ( const obdeque deque)

Peek at the obj stored at the head of an obdeque.

Parameters
dequeAn instance of obdeque
Return values
NULLNo elements exist within deque
non-NULLThe element stored at the head of deque
obj* obdeque_obj_at_iterator ( const obdeque deque,
const obdeque_iterator it 
)

Peek at the obj stored within a obdeque stored at the position denoted by an obdeque_iterator bound to that obdeque.

Parameters
dequeAn instance of obdeque
itAn instance of obdeque_iterator bound to deque
Return values
NULLNo elements exist within deque
non-NULLThe element stored at the tail of deque
obj* obdeque_obj_at_tail ( const obdeque deque)

Peek at the obj stored at the tail of an obdeque.

Parameters
dequeAn instance of obdeque
Return values
NULLNo elements exist within deque
non-NULLThe element stored at the tail of deque
void obdeque_remove_at_iterator ( obdeque deque,
obdeque_iterator it 
)

Remove the obj stored within an obdeque at the position denoted by the obdeque_iterator bound to that obdeque, shrinking the obdeque by one element.

Parameters
dequeAn instance of obdeque
itAn instance of obdeque_iterator bound to deque

The provided obdeque_iterator will be advanced toward the obdeque tail, unless removing the tail then it will be advanced to the element before the tail (NULL if no more elements exist)

void obdeque_remove_head ( obdeque deque)

Remove the obj stored at the head of an obdeque, shrinking the obdeque by one element.

Parameters
dequeAn instance of obdeque
void obdeque_remove_tail ( obdeque deque)

Remove the obj stored at the tail of an obdeque, shrinking the obdeque by one element.

Parameters
dequeAn instance of obdeque
void obdeque_sort ( obdeque deque,
int8_t  order 
)

Sorts an obdeque from least-to-greatest or greatest-to-least using the standard compare function.

Parameters
dequeAn instance of obdeque
orderAccepts OB_LEAST_TO_GREATEST or OB_GREATEST_TO_LEAST as valid sorting orders
Warning
If called on an obdeque containing instances of multiple Offbrand compatible classes the call will likely not sort members in any expected order, but will reorder components
void obdeque_sort_with_funct ( obdeque deque,
int8_t  order,
ob_compare_fptr  funct 
)

Sorts an obdeque from least-to-greatest or greatest-to-least using a specified comparision function.

Parameters
dequeAn instance of obdeque
orderAccepts OB_LEAST_TO_GREATEST or OB_GREATEST_TO_LEAST as valid sorting orders
functA pointer to a comparision function that returns a int8_t when given two obj * arguments
obdeque_iterator* obdeque_tail_iterator ( const obdeque deque)

Constructor for an iterator for an obdeque that is directed at the tail of the obdeque.

Parameters
dequeAn instance of obdeque
Return values
NULLThe obdeque provided is empty and cannot be iterated
non-NULLAn obdeque_iterator instance bound to the provided instance and directed at the tail of that obdeque
Warning
The obdeque_iterator created by this method MUST be released by the user, else a memory leak will occur