From 0aa5e838fca48b8e3e00c90fba26590b521f4403 Mon Sep 17 00:00:00 2001 From: erickson Date: Fri, 3 Mar 2006 15:13:23 +0000 Subject: [PATCH] added method to insert items at the first NULL slot in the list. useful for removing random items and inserting random items where order is not necessary git-svn-id: svn://svn.open-ils.org/OpenSRF/trunk@656 9efc2488-bf62-4759-914b-345cdb29e865 --- src/libstack/osrf_list.c | 9 +++++++++ src/libstack/osrf_list.h | 6 ++++++ 2 files changed, 15 insertions(+) diff --git a/src/libstack/osrf_list.c b/src/libstack/osrf_list.c index 9b2de0f..9cfd89f 100644 --- a/src/libstack/osrf_list.c +++ b/src/libstack/osrf_list.c @@ -25,6 +25,15 @@ int osrfListPush( osrfList* list, void* item ) { return 0; } +int osrfListPushFirst( osrfList* list, void* item ) { + if(!(list && item)) return -1; + int i; + for( i = 0; i < list->size; i++ ) + if(!list->arrlist[i]) break; + osrfListSet( list, item, i ); + return list->size; +} + void* osrfListSet( osrfList* list, void* item, unsigned int position ) { if(!list || position < 0) return NULL; diff --git a/src/libstack/osrf_list.h b/src/libstack/osrf_list.h index e936d1c..99ede9f 100644 --- a/src/libstack/osrf_list.h +++ b/src/libstack/osrf_list.h @@ -142,5 +142,11 @@ void osrfListVanillaFree( void* item ); */ void osrfListSetDefaultFree( osrfList* list ); +/** + * Inserts the new item at the first free (null) slot + * in the array. Item is shoved onto the end of the + * list if there are no null slots */ +int osrfListPushFirst( osrfList* list, void* item ); + #endif -- 2.11.0