2018-12-07 06:40:43 +08:00
|
|
|
/* Copyright 2018, UCAR/Unidata and OPeNDAP, Inc.
|
2012-08-20 05:54:30 +08:00
|
|
|
See the COPYRIGHT file for more information. */
|
2010-06-03 21:24:43 +08:00
|
|
|
#ifndef LIST_H
|
|
|
|
#define LIST_H 1
|
|
|
|
|
2012-08-20 05:54:30 +08:00
|
|
|
/* Define the type of the elements in the list*/
|
2010-06-03 21:24:43 +08:00
|
|
|
|
|
|
|
#if defined(_CPLUSPLUS_) || defined(__CPLUSPLUS__)
|
|
|
|
#define EXTERNC extern "C"
|
|
|
|
#else
|
|
|
|
#define EXTERNC extern
|
|
|
|
#endif
|
|
|
|
|
2012-08-20 05:54:30 +08:00
|
|
|
EXTERNC int listnull(void*);
|
2010-06-03 21:24:43 +08:00
|
|
|
|
|
|
|
typedef struct List {
|
2012-08-20 05:54:30 +08:00
|
|
|
unsigned long alloc;
|
|
|
|
unsigned long length;
|
|
|
|
void** content;
|
2010-06-03 21:24:43 +08:00
|
|
|
} List;
|
|
|
|
|
|
|
|
EXTERNC List* listnew(void);
|
|
|
|
EXTERNC int listfree(List*);
|
2012-08-20 05:54:30 +08:00
|
|
|
EXTERNC int listsetalloc(List*,unsigned long);
|
|
|
|
EXTERNC int listsetlength(List*,unsigned long);
|
|
|
|
|
|
|
|
/* Set the ith element */
|
|
|
|
EXTERNC int listset(List*,unsigned long,void*);
|
|
|
|
/* Get value at position i */
|
|
|
|
EXTERNC void* listget(List*,unsigned long);/* Return the ith element of l */
|
|
|
|
/* Insert at position i; will push up elements i..|seq|. */
|
|
|
|
EXTERNC int listinsert(List*,unsigned long,void*);
|
|
|
|
/* Remove element at position i; will move higher elements down */
|
|
|
|
EXTERNC void* listremove(List* l, unsigned long i);
|
2010-06-03 21:24:43 +08:00
|
|
|
|
|
|
|
/* Tail operations */
|
2012-08-20 05:54:30 +08:00
|
|
|
EXTERNC int listpush(List*,void*); /* Add at Tail */
|
|
|
|
EXTERNC void* listpop(List*);
|
|
|
|
EXTERNC void* listtop(List*);
|
2010-06-03 21:24:43 +08:00
|
|
|
|
|
|
|
/* Duplicate and return the content (null terminate) */
|
2012-08-20 05:54:30 +08:00
|
|
|
EXTERNC void** listdup(List*);
|
2010-06-03 21:24:43 +08:00
|
|
|
|
2012-08-20 05:54:30 +08:00
|
|
|
/* Look for value match */
|
|
|
|
EXTERNC int listcontains(List*, void*);
|
2010-06-03 21:24:43 +08:00
|
|
|
|
2012-08-20 05:54:30 +08:00
|
|
|
/* Remove element by value; only removes first encountered */
|
|
|
|
EXTERNC int listelemremove(List* l, void* elem);
|
2010-06-03 21:24:43 +08:00
|
|
|
|
2012-08-20 05:54:30 +08:00
|
|
|
/* remove duplicates */
|
|
|
|
EXTERNC int listunique(List*);
|
2010-06-03 21:24:43 +08:00
|
|
|
|
2012-08-20 05:54:30 +08:00
|
|
|
/* Create a clone of a list */
|
|
|
|
EXTERNC List* listclone(List*);
|
2010-06-03 21:24:43 +08:00
|
|
|
|
2012-08-20 05:54:30 +08:00
|
|
|
/* Following are always "in-lined"*/
|
|
|
|
#define listclear(l) listsetlength((l),0)
|
|
|
|
#define listextend(l,len) listsetalloc((l),(len)+(l->alloc))
|
|
|
|
#define listcontents(l) ((l)==NULL?NULL:(l)->content)
|
2012-08-28 05:19:25 +08:00
|
|
|
#define listlength(l) ((l)==NULL?0:(int)(l)->length)
|
2010-06-03 21:24:43 +08:00
|
|
|
|
|
|
|
#endif /*LIST_H*/
|