1 /**************************************************************************
3 * Copyright 2008 VMware, Inc.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 **************************************************************************/
29 #include "util/u_pointer.h"
30 #include "util/u_hash_table.h"
38 pointer_hash(const void *key
)
40 return _mesa_hash_pointer(key
);
45 pointer_equal(const void *a
, const void *b
)
52 util_hash_table_create_ptr_keys(void)
54 return _mesa_hash_table_create(NULL
, pointer_hash
, pointer_equal
);
58 static uint32_t hash_fd(const void *key
)
61 int fd
= pointer_to_intptr(key
);
66 return stat
.st_dev
^ stat
.st_ino
^ stat
.st_rdev
;
73 static bool equal_fd(const void *key1
, const void *key2
)
76 int fd1
= pointer_to_intptr(key1
);
77 int fd2
= pointer_to_intptr(key2
);
78 struct stat stat1
, stat2
;
83 return stat1
.st_dev
== stat2
.st_dev
&&
84 stat1
.st_ino
== stat2
.st_ino
&&
85 stat1
.st_rdev
== stat2
.st_rdev
;
93 util_hash_table_create_fd_keys(void)
95 return _mesa_hash_table_create(NULL
, hash_fd
, equal_fd
);
100 util_hash_table_get(struct hash_table
*ht
,
103 struct hash_entry
*entry
= _mesa_hash_table_search(ht
, key
);
105 return entry
? entry
->data
: NULL
;
110 util_hash_table_foreach(struct hash_table
*ht
,
111 enum pipe_error (*callback
)
112 (void *key
, void *value
, void *data
),
115 hash_table_foreach(ht
, entry
) {
116 enum pipe_error error
= callback((void*)entry
->key
, entry
->data
, data
);
117 if (error
!= PIPE_OK
)