1 #include <opensrf/osrf_big_list.h>
4 osrfBigList* osrfNewBigList() {
5 osrfBigList* list = safe_malloc(sizeof(osrfBigList));
6 list->list = (Pvoid_t) NULL;
13 int osrfBigListPush( osrfBigList* list, void* item ) {
14 if(!(list && item)) return -1;
16 unsigned long index = -1;
17 JLL(value, list->list, index );
18 osrfBigListSet( list, item, index+1 );
23 void* osrfBigListSet( osrfBigList* list, void* item, unsigned long position ) {
24 if(!list || position < 0) return NULL;
27 void* olditem = osrfBigListRemove( list, position );
29 JLI( value, list->list, position );
30 *value = (Word_t) item;
31 __osrfBigListSetSize( list );
37 void* osrfBigListGetIndex( osrfBigList* list, unsigned long position ) {
38 if(!list) return NULL;
41 JLG( value, list->list, position );
42 if(value) return (void*) *value;
46 void osrfBigListFree( osrfBigList* list ) {
50 unsigned long index = -1;
51 JLL(value, list->list, index );
54 while (value != NULL) {
56 list->freeItem( (void*) *value );
57 JLD(retcode, list->list, index);
58 JLP(value, list->list, index);
64 void* osrfBigListRemove( osrfBigList* list, int position ) {
65 if(!list) return NULL;
69 JLG( value, list->list, position );
74 olditem = (void*) *value;
76 JLD(retcode, list->list, position );
79 list->freeItem( olditem );
82 __osrfBigListSetSize( list );
91 int osrfBigListFind( osrfBigList* list, void* addr ) {
92 if(!(list && addr)) return -1;
95 unsigned long index = -1;
96 JLL(value, list->list, index );
98 while (value != NULL) {
99 if( (void*) *value == addr )
101 JLP(value, list->list, index);
109 void __osrfBigListSetSize( osrfBigList* list ) {
113 unsigned long index = -1;
114 JLL(value, list->list, index );
115 list->size = index + 1;
119 unsigned long osrfBigListGetCount( osrfBigList* list ) {
121 unsigned long retcode = -1;
122 JLC( retcode, list->list, 0, -1 );
127 void* osrfBigListPop( osrfBigList* list ) {
128 if(!list) return NULL;
129 return osrfBigListRemove( list, list->size - 1 );
133 osrfBigBigListIterator* osrfNewBigListIterator( osrfBigList* list ) {
134 if(!list) return NULL;
135 osrfBigBigListIterator* itr = safe_malloc(sizeof(osrfBigBigListIterator));
141 void* osrfBigBigListIteratorNext( osrfBigBigListIterator* itr ) {
142 if(!(itr && itr->list)) return NULL;
145 if(itr->current >= itr->list->size) return NULL;
146 JLF( value, itr->list->list, itr->current );
149 return (void*) *value;
154 void osrfBigBigListIteratorFree( osrfBigBigListIterator* itr ) {
161 void osrfBigBigListIteratorReset( osrfBigBigListIterator* itr ) {
167 void osrfBigListVanillaFree( void* item ) {
171 void osrfBigListSetDefaultFree( osrfBigList* list ) {
173 list->freeItem = osrfBigListVanillaFree;