72 if (ih < 0 || (
unsigned)ih >= hset->
cap)
return 0;
73 if (hset->
p[ih])
return 1;
84 hset = malloc(
sizeof (*hset));
86 hset->
p = malloc((
unsigned)cap *
sizeof(
void*));
88 hset->
cap = (unsigned)cap;
91 for (
unsigned i=0; i<(unsigned)cap; i++) {
105 unsigned old_cap, new_cap;
113 hset->
p =
xrealloc(hset->
p, (
unsigned)new_cap *
sizeof(
void*));
115 for (
unsigned i=old_cap; i<new_cap; i++) {
131 if (p == NULL)
return -1;
134 for (
unsigned j=0; j<hset->
cap; j++) {
135 unsigned i = (hset->
hnf + j) % hset->
cap;
138 hset->
hnf = (i+1) % hset->
cap;
144 die(
"internal error");
153 hset->
p[handle]=NULL;
154 if (hset->
num == 0)
die(
"delete_handle: internal error - negative occupation count");
156 if (hset->
p[hset->
hnf]) hset->
hnf = (unsigned)handle;
add versions of standard API functions not returning on error
#define xrealloc(ptr, size)
int xt_handle_is_valid(Xt_handle_set_type hset, int ih)
Xt_handle_set_type xt_handle_set_new(int cap)
void xt_handle_set_delete(Xt_handle_set_type hset)
static void extend_handle_set(Xt_handle_set_type hset)
int xt_handle_new(Xt_handle_set_type hset, void *p)
void xt_handle_delete(Xt_handle_set_type hset, int handle)
static const unsigned default_handle_set_cap
void * xt_handle2pointer(Xt_handle_set_type hset, int ih)
maps integers to data pointers