blob: e763453ebf5052728f044b75cc593283fc77d34a [file] [log] [blame]
Kristian Høgsberg97f1ebe2008-09-30 09:46:10 -04001#include <stdlib.h>
2#include "wayland.h"
3
4int wl_hash_insert(struct wl_hash *hash, struct wl_object *object)
5{
6 struct wl_object **objects;
7 uint32_t alloc;
8
9 if (hash->count == hash->alloc) {
10 if (hash->alloc == 0)
11 alloc = 16;
12 else
13 alloc = hash->alloc * 2;
14 objects = realloc(hash->objects, alloc * sizeof *objects);
15 if (objects == NULL)
16 return -1;
17
18 hash->objects = objects;
19 hash->alloc = alloc;
20 }
21
22 hash->objects[hash->count] = object;
23 hash->count++;
24
25 return 0;
26}
27
28struct wl_object *
29wl_hash_lookup(struct wl_hash *hash, uint32_t id)
30{
31 int i;
32
33 for (i = 0; i < hash->count; i++) {
34 if (hash->objects[i]->id == id)
35 return hash->objects[i];
36 }
37
38 return NULL;
39}
40
41void
42wl_hash_delete(struct wl_hash *hash, struct wl_object *object)
43{
44 /* writeme */
45}
Kristian Høgsberg1e4b86a2008-11-23 23:41:08 -050046
47
48void wl_list_init(struct wl_list *list)
49{
50 list->prev = list;
51 list->next = list;
52}
53
54void
55wl_list_insert(struct wl_list *list, struct wl_list *elm)
56{
57 elm->prev = list;
58 elm->next = list->next;
59 list->next = elm;
60 elm->next->prev = elm;
61}
62
63void
64wl_list_remove(struct wl_list *elm)
65{
66 elm->prev->next = elm->next;
67 elm->next->prev = elm->prev;
68}
69
70int
71wl_list_length(struct wl_list *list)
72{
73 struct wl_list *e;
74 int count;
75
76 e = list->next;
77 while (e != list) {
78 e = e->next;
79 count++;
80 }
81
82 return count;
83}