Kristian Høgsberg | 97f1ebe | 2008-09-30 09:46:10 -0400 | [diff] [blame] | 1 | #include <stdlib.h> |
| 2 | #include "wayland.h" |
| 3 | |
| 4 | int 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 | |
| 28 | struct wl_object * |
| 29 | wl_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 | |
| 41 | void |
| 42 | wl_hash_delete(struct wl_hash *hash, struct wl_object *object) |
| 43 | { |
| 44 | /* writeme */ |
| 45 | } |
Kristian Høgsberg | 1e4b86a | 2008-11-23 23:41:08 -0500 | [diff] [blame] | 46 | |
| 47 | |
| 48 | void wl_list_init(struct wl_list *list) |
| 49 | { |
| 50 | list->prev = list; |
| 51 | list->next = list; |
| 52 | } |
| 53 | |
| 54 | void |
| 55 | wl_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 | |
| 63 | void |
| 64 | wl_list_remove(struct wl_list *elm) |
| 65 | { |
| 66 | elm->prev->next = elm->next; |
| 67 | elm->next->prev = elm->prev; |
| 68 | } |
| 69 | |
| 70 | int |
| 71 | wl_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 | } |