1
0
mirror of https://github.com/cc65/cc65.git synced 2024-06-26 20:29:34 +00:00
cc65/src/common/coll.h
cuz b9970cb7da Working on the condes feature
git-svn-id: svn://svn.cc65.org/cc65/trunk@451 b7a2c559-68d2-44c3-8de9-860c34a00d81
2000-11-20 15:22:57 +00:00

134 lines
5.1 KiB
C

/*****************************************************************************/
/* */
/* coll.h */
/* */
/* Collection (dynamic array) */
/* */
/* */
/* */
/* (C) 2000 Ullrich von Bassewitz */
/* Wacholderweg 14 */
/* D-70597 Stuttgart */
/* EMail: uz@musoftware.de */
/* */
/* */
/* This software is provided 'as-is', without any expressed or implied */
/* warranty. In no event will the authors be held liable for any damages */
/* arising from the use of this software. */
/* */
/* Permission is granted to anyone to use this software for any purpose, */
/* including commercial applications, and to alter it and redistribute it */
/* freely, subject to the following restrictions: */
/* */
/* 1. The origin of this software must not be misrepresented; you must not */
/* claim that you wrote the original software. If you use this software */
/* in a product, an acknowledgment in the product documentation would be */
/* appreciated but is not required. */
/* 2. Altered source versions must be plainly marked as such, and must not */
/* be misrepresented as being the original software. */
/* 3. This notice may not be removed or altered from any source */
/* distribution. */
/* */
/*****************************************************************************/
#ifndef COLL_H
#define COLL_H
#include "attrib.h"
/*****************************************************************************/
/* Data */
/*****************************************************************************/
/* An array of pointers that grows if needed */
typedef struct Collection Collection;
struct Collection {
unsigned Count; /* Number of items in the list */
unsigned Size; /* Size of allocated array */
void** Items; /* Array with dynamic size */
};
/* Initializer for static collections */
#define STATIC_COLLECTION_INITIALIZER { 0, 0, 0 }
/*****************************************************************************/
/* Code */
/*****************************************************************************/
Collection* InitCollection (Collection* C);
/* Initialize a collection and return it. */
void DoneCollection (Collection* C);
/* Free the data for a collection. This will not free the data contained in
* the collection.
*/
Collection* NewCollection (void);
/* Create and return a new collection */
void FreeCollection (Collection* C);
/* Free a collection */
unsigned CollCount (const Collection* C);
/* Return the number of items in the collection */
void CollInsert (Collection* C, void* Item, unsigned Index);
/* Insert the data at the given position in the collection */
void CollAppend (Collection* C, void* Item);
/* Append an item to the end of the collection */
void* CollAt (Collection* C, unsigned Index) attribute ((const));
/* Return the item at the given index */
const void* CollConstAt (const Collection* C, unsigned Index) attribute ((const));
/* Return the item at the given index */
void* CollLast (Collection* C);
/* Return the last item in a collection */
const void* CollConstLast (const Collection* C);
/* Return the last item in a collection */
void CollDelete (Collection* C, unsigned Index);
/* Remove the item with the given index from the collection. This will not
* free the item itself, just the pointer. All items with higher indices
* will get moved to a lower position.
*/
void CollReplace (Collection* C, void* Item, unsigned Index);
/* Replace the item at the given position. The old item will not be freed,
* just the pointer will et replaced.
*/
void CollSort (Collection* C,
int (*Compare) (void*, const void*, const void*),
void* Data);
/* Sort the collection using the given compare function. The data pointer is
* passed as *first* element to the compare function, it's not used by the
* sort function itself. The other two pointer passed to the Compare function
* are pointers to objects.
*/
/* End of exprlist.h */
#endif