src/server/list.h

Sun, 30 Oct 2011 16:26:57 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sun, 30 Oct 2011 16:26:57 +0100
changeset 3
137197831306
parent 1
3c066d52342d
permissions
-rw-r--r--

minimal request handling

/*
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
 *
 * Copyright 2011 Olaf Wintermann. All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 *   1. Redistributions of source code must retain the above copyright
 *      notice, this list of conditions and the following disclaimer.
 *
 *   2. Redistributions in binary form must reproduce the above copyright
 *      notice, this list of conditions and the following disclaimer in the
 *      documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */

#ifndef LIST_H
#define	LIST_H

#ifdef	__cplusplus
extern "C" {
#endif

typedef struct _util_slist sdlist_t;

struct _util_slist {
    void *data;
    sdlist_t *next;
};

typedef int (*sdlist_iterator_func)(sdlist_t*, void*);


/* single linked list */

/*
 * sdlist_add/sdllist_addl
 *
 * append to the end of the list one element
 */
sdlist_t* sdlist_add(sdlist_t *list, void *data);
sdlist_t* sdlist_addl(sdlist_t *list, sdlist_t *l);
    
/*
 * sdlist_remove/sdlist_removei
 *
 * remove one element from the list and free the sdlist_t object
 * returns the first element of the new list
 */
sdlist_t* sdlist_remove(sdlist_t *list, void *data);
sdlist_t* sdlist_removei(sdlist_t *list, int index);

/*
 * sdlist_removel
 *
 * remove element l from the list
 * returns the first element of the new list
 */
sdlist_t* sdlist_removel(sdlist_t *list, sdlist_t *l);

/*
 * removes one element from the list
 *
 * list:   list
 * prev:   previous to elm
 * elm:    element which should be removed
 *
 * returns the first element of the new list
 */
sdlist_t *sdlist_remove_elm(sdlist_t *list, sdlist_t *prev, sdlist_t *elm);
    

/*
 * sdlist_insert
 *
 * insert one element after the element elm
 */
void sdlist_insert(sdlist_t *elm, void *data);
void sdlist_insertl(sdlist_t *elm, sdlist_t *l);

sdlist_t* sdlist_get(sdlist_t *list, void *data);
sdlist_t* sdlist_geti(sdlist_t *list, int index);
sdlist_t* sdlist_getlast(sdlist_t *list);

size_t sdlist_length(sdlist_t *list);
void sdlist_free(sdlist_t *elm);
void sdlist_foreach(sdlist_t *list, sdlist_iterator_func f, void *data);

#ifdef	__cplusplus
}
#endif

#endif	/* LIST_H */

mercurial