2 * Copyright © 2008 Kristian Høgsberg
4 * Permission to use, copy, modify, distribute, and sell this software and its
5 * documentation for any purpose is hereby granted without fee, provided that
6 * the above copyright notice appear in all copies and that both that copyright
7 * notice and this permission notice appear in supporting documentation, and
8 * that the name of the copyright holders not be used in advertising or
9 * publicity pertaining to distribution of the software without specific,
10 * written prior permission. The copyright holders make no representations
11 * about the suitability of this software for any purpose. It is provided "as
12 * is" without express or implied warranty.
14 * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
15 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
16 * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
17 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
18 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
19 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
26 #include "wayland-util.h"
29 struct wl_object **objects;
30 uint32_t count, alloc;
38 hash = malloc(sizeof *hash);
42 memset(hash, 0, sizeof *hash);
48 wl_hash_destroy(struct wl_hash *hash)
53 int wl_hash_insert(struct wl_hash *hash, struct wl_object *object)
55 struct wl_object **objects;
58 if (hash->count == hash->alloc) {
62 alloc = hash->alloc * 2;
63 objects = realloc(hash->objects, alloc * sizeof *objects);
67 hash->objects = objects;
71 hash->objects[hash->count] = object;
78 wl_hash_lookup(struct wl_hash *hash, uint32_t id)
82 for (i = 0; i < hash->count; i++) {
83 if (hash->objects[i]->id == id)
84 return hash->objects[i];
91 wl_hash_delete(struct wl_hash *hash, struct wl_object *object)
97 void wl_list_init(struct wl_list *list)
104 wl_list_insert(struct wl_list *list, struct wl_list *elm)
107 elm->next = list->next;
109 elm->next->prev = elm;
113 wl_list_remove(struct wl_list *elm)
115 elm->prev->next = elm->next;
116 elm->next->prev = elm->prev;
120 wl_list_length(struct wl_list *list)
136 wl_list_empty(struct wl_list *list)
138 return list->next == list;