![]() |
Icinga-core 1.4.0
next gen monitoring
|
00001 /************************************************************************ 00002 * 00003 * SKIPLIST.H - Skiplist data structures and functions 00004 * 00005 * Copyright (c) 1999-2009 Ethan Galstad (egalstad@nagios.org) 00006 * Copyright (c) 2009-2011 Nagios Core Development Team and Community Contributors 00007 * Copyright (c) 2009-2011 Icinga Development Team (http://www.icinga.org) 00008 * 00009 * License: 00010 * 00011 * This program is free software; you can redistribute it and/or modify 00012 * it under the terms of the GNU General Public License version 2 as 00013 * published by the Free Software Foundation. 00014 * 00015 * This program is distributed in the hope that it will be useful, 00016 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00018 * GNU General Public License for more details. 00019 * 00020 * You should have received a copy of the GNU General Public License 00021 * along with this program; if not, write to the Free Software 00022 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00023 ************************************************************************/ 00024 00025 #ifndef _SKIPLIST_H 00026 #define _SKIPLIST_H 00027 00028 #define SKIPLIST_OK 0 00029 #define SKIPLIST_ERROR_ARGS 1 00030 #define SKIPLIST_ERROR_MEMORY 2 00031 #define SKIPLIST_ERROR_DUPLICATE 3 00032 00033 00034 typedef struct skiplistnode_struct{ 00035 void *data; 00036 struct skiplistnode_struct *forward[1]; /* this must be the last element of the struct, as we allocate # of elements during runtime*/ 00037 }skiplistnode; 00038 00039 typedef struct skiplist_struct{ 00040 int current_level; 00041 int max_levels; 00042 float level_probability; 00043 unsigned long items; 00044 int allow_duplicates; 00045 int append_duplicates; 00046 int (*compare_function)(void *,void *); 00047 skiplistnode *head; 00048 }skiplist; 00049 00050 00051 skiplist *skiplist_new(int max_levels, float level_probability, int allow_duplicates, int append_duplicates, int (*compare_function)(void *,void *)); 00052 skiplistnode *skiplist_new_node(skiplist *list,int node_levels); 00053 int skiplist_insert(skiplist *list, void *data); 00054 int skiplist_random_level(skiplist *list); 00055 int skiplist_empty(skiplist *list); 00056 int skiplist_free(skiplist **list); 00057 void *skiplist_peek(skiplist *); 00058 void *skiplist_pop(skiplist *); 00059 void *skiplist_get_first(skiplist *list, void **node_ptr); 00060 void *skiplist_get_next(void **node_ptr); 00061 void *skiplist_find_first(skiplist *list, void *data, void **node_ptr); 00062 void *skiplist_find_next(skiplist *list, void *data, void **node_ptr); 00063 int skiplist_delete(skiplist *list, void *data); 00064 int skiplist_delete_first(skiplist *list, void *data); 00065 int skiplist_delete_all(skiplist *list, void *data); 00066 int skiplist_delete_node(skiplist *list, void *node_ptr); 00067 00068 #endif