1235783Skib/**************************************************************************
2235783Skib *
3235783Skib * Copyright 2006 Tungsten Graphics, Inc., Bismack, ND. USA.
4235783Skib * All Rights Reserved.
5235783Skib *
6235783Skib * Permission is hereby granted, free of charge, to any person obtaining a
7235783Skib * copy of this software and associated documentation files (the
8235783Skib * "Software"), to deal in the Software without restriction, including
9235783Skib * without limitation the rights to use, copy, modify, merge, publish,
10235783Skib * distribute, sub license, and/or sell copies of the Software, and to
11235783Skib * permit persons to whom the Software is furnished to do so, subject to
12235783Skib * the following conditions:
13235783Skib *
14235783Skib * The above copyright notice and this permission notice (including the
15235783Skib * next paragraph) shall be included in all copies or substantial portions
16235783Skib * of the Software.
17235783Skib *
18235783Skib * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19235783Skib * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20235783Skib * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
21235783Skib * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
22235783Skib * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
23235783Skib * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
24235783Skib * USE OR OTHER DEALINGS IN THE SOFTWARE.
25235783Skib *
26235783Skib *
27235783Skib **************************************************************************/
28235783Skib
29235783Skib#include <sys/cdefs.h>
30235783Skib__FBSDID("$FreeBSD$");
31235783Skib
32235783Skib/*
33235783Skib * Simple open hash tab implementation.
34235783Skib *
35235783Skib * Authors:
36235783Skib * Thomas Hellstr��m <thomas-at-tungstengraphics-dot-com>
37235783Skib */
38235783Skib
39235783Skib#ifndef DRM_HASHTAB_H
40235783Skib#define DRM_HASHTAB_H
41235783Skib
42235783Skib#define drm_hash_entry(_ptr, _type, _member) container_of(_ptr, _type, _member)
43235783Skib
44235783Skibstruct drm_hash_item {
45235783Skib	LIST_ENTRY(drm_hash_item) head;
46235783Skib	unsigned long key;
47235783Skib};
48235783Skib
49235783Skibstruct drm_open_hash {
50235783Skib	LIST_HEAD(drm_hash_item_list, drm_hash_item) *table;
51235783Skib	unsigned int size;
52235783Skib	unsigned int order;
53235783Skib	unsigned long mask;
54235783Skib};
55235783Skib
56235783Skibextern int drm_ht_create(struct drm_open_hash *ht, unsigned int order);
57235783Skibextern int drm_ht_insert_item(struct drm_open_hash *ht, struct drm_hash_item *item);
58235783Skibextern int drm_ht_just_insert_please(struct drm_open_hash *ht, struct drm_hash_item *item,
59235783Skib				     unsigned long seed, int bits, int shift,
60235783Skib				     unsigned long add);
61235783Skibextern int drm_ht_find_item(struct drm_open_hash *ht, unsigned long key, struct drm_hash_item **item);
62235783Skib
63235783Skibextern void drm_ht_verbose_list(struct drm_open_hash *ht, unsigned long key);
64235783Skibextern int drm_ht_remove_key(struct drm_open_hash *ht, unsigned long key);
65235783Skibextern int drm_ht_remove_item(struct drm_open_hash *ht, struct drm_hash_item *item);
66235783Skibextern void drm_ht_remove(struct drm_open_hash *ht);
67235783Skib
68235783Skib#endif
69