Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/agent/src/os/linux/hsearch/search.h
38841 views
/*-1* Written by J.T. Conklin <[email protected]>2* Public domain.3*4* $NetBSD: search.h,v 1.12 1999/02/22 10:34:28 christos Exp $5* $FreeBSD: release/9.0.0/include/search.h 105250 2002-10-16 14:29:23Z robert $6*/7#pragma once8/**9* @file search.h10* @brief Queues, hash tables, trees, and linear array searches.11*/12#include <sys/cdefs.h>13#include <sys/types.h>14/** See hsearch()/hsearch_r(). */15typedef enum {16FIND,17ENTER18} ACTION;19/** See hsearch()/hsearch_r(). */20typedef struct entry {21/** The string key. */22char* key;23/** The associated data. */24void* data;25} ENTRY;26/**27* Constants given to the twalk() visitor.28* Note that the constant names are misleading.29*/30typedef enum {31/**32* If this is the first visit to a non-leaf node.33* Use this for *preorder* traversal.34*/35preorder,36/**37* If this is the second visit to a non-leaf node.38* Use this for *inorder* traversal.39*/40postorder,41/**42* If this is the third visit to a non-leaf node.43* Use this for *postorder* traversal.44*/45endorder,46/** If this is the first and only visit to a leaf node. */47leaf48} VISIT;49// #if defined(__USE_BSD) || defined(__USE_GNU)50/** The hash table type for hcreate_r()/hdestroy_r()/hsearch_r(). */51struct hsearch_data {52struct __hsearch* __hsearch;53};54//#endif55__BEGIN_DECLS56/**57* [insque(3)](http://man7.org/linux/man-pages/man3/insque.3.html) inserts58* an item in a queue (an intrusive doubly-linked list).59*60* Available since API level 21.61*/62void insque(void* __element, void* __previous); // __INTRODUCED_IN(21);63/**64* [remque(3)](http://man7.org/linux/man-pages/man3/remque.3.html) removes65* an item from a queue (an intrusive doubly-linked list).66*67* Available since API level 21.68*/69void remque(void* __element); // __INTRODUCED_IN(21);70/**71* [hcreate(3)](http://man7.org/linux/man-pages/man3/hcreate.3.html)72* initializes the global hash table, with space for at least `__n` elements.73*74* See hcreate_r() if you need more than one hash table.75*76* Returns *non-zero* on success and returns 0 and sets `errno` on failure.77*78* Available since API level 28.79*/80int hcreate(size_t __n); // __INTRODUCED_IN(28);81/**82* [hdestroy(3)](http://man7.org/linux/man-pages/man3/hdestroy.3.html) destroys83* the global hash table.84*85* See hdestroy_r() if you need more than one hash table.86*87* Available since API level 28.88*/89void hdestroy(void); // __INTRODUCED_IN(28);90/**91* [hsearch(3)](http://man7.org/linux/man-pages/man3/hsearch.3.html) finds or92* inserts `__entry` in the global hash table, based on `__action`.93*94* See hsearch_r() if you need more than one hash table.95*96* Returns a pointer to the entry on success, and returns NULL and sets97* `errno` on failure.98*99* Available since API level 28.100*/101ENTRY* hsearch(ENTRY __entry, ACTION __action); // __INTRODUCED_IN(28);102// #if defined(__USE_BSD) || defined(__USE_GNU)103/**104* [hcreate_r(3)](http://man7.org/linux/man-pages/man3/hcreate_r.3.html)105* initializes a hash table `__table` with space for at least `__n` elements.106*107* Returns *non-zero* on success and returns 0 and sets `errno` on failure.108*109* Available since API level 28.110*/111int hcreate_r(size_t __n, struct hsearch_data* __table); // __INTRODUCED_IN(28);112/**113* [hdestroy_r(3)](http://man7.org/linux/man-pages/man3/hdestroy_r.3.html) destroys114* the hash table `__table`.115*116* Available since API level 28.117*/118void hdestroy_r(struct hsearch_data* __table); // __INTRODUCED_IN(28);119/**120* [hsearch_r(3)](http://man7.org/linux/man-pages/man3/hsearch_r.3.html) finds or121* inserts `__entry` in the hash table `__table`, based on `__action`.122*123* Returns *non-zero* on success and returns 0 and sets `errno` on failure.124* A pointer to the entry is returned in `*__result`.125*126* Available since API level 28.127*/128int hsearch_r(ENTRY __entry, ACTION __action, ENTRY** __result, struct hsearch_data* __table); // __INTRODUCED_IN(28);129// #endif130/**131* [lfind(3)](http://man7.org/linux/man-pages/man3/lfind.3.html) brute-force132* searches the unsorted array `__array` (of `__count` items each of size `__size`)133* for `__key`, using `__comparator`.134*135* See bsearch() if you have a sorted array.136*137* Returns a pointer to the matching element on success, or NULL on failure.138*139* Available since API level 21.140*/141void* lfind(const void* __key, const void* __array, size_t* __count, size_t __size, int (*__comparator)(const void*, const void*)); // __INTRODUCED_IN(21);142/**143* [lsearch(3)](http://man7.org/linux/man-pages/man3/lsearch.3.html) brute-force144* searches the unsorted array `__array` (of `__count` items each of size `__size`)145* for `__key`, using `__comparator`.146*147* Unlike lfind(), on failure lsearch() will *insert* `__key` at the end of148* `__array` and increment `*__count`.149*150* Returns a pointer to the matching element on success, or to the newly-added151* element on failure.152*153* Available since API level 21.154*/155void* lsearch(const void* __key, void* __array, size_t* __count, size_t __size, int (*__comparator)(const void*, const void*)); // __INTRODUCED_IN(21);156/**157* [tdelete(3)](http://man7.org/linux/man-pages/man3/tdelete.3.html) searches158* for and removes an element in the tree `*__root_ptr`. The search is performed159* using `__comparator`.160*161* Returns a pointer to the parent of the deleted node, or NULL on failure.162*/163void* tdelete(const void* __key, void** __root_ptr, int (*__comparator)(const void*, const void*));164/**165* [tdestroy(3)](http://man7.org/linux/man-pages/man3/tdestroy.3.html) destroys166* the hash table `__root` using `__free_fn` on each node.167*/168void tdestroy(void* __root, void (*__free_fn)(void*));169/**170* [tfind(3)](http://man7.org/linux/man-pages/man3/tfind.3.html) searches171* for an element in the tree `*__root_ptr`. The search is performed using172* `__comparator`.173*174* Returns a pointer to the matching node, or NULL on failure.175*/176void* tfind(const void* __key, void* const* __root_ptr, int (*__comparator)(const void*, const void*));177/**178* [tsearch(3)](http://man7.org/linux/man-pages/man3/tsearch.3.html) searches179* for an element in the tree `*__root_ptr`. The search is performed using180* `__comparator`.181*182* Unlike tfind(), on failure tsearch() will *insert* `__key` into the tree.183*184* Returns a pointer to the matching node, or to the newly-added node.185*/186void* tsearch(const void* __key, void** __root_ptr, int (*__comparator)(const void*, const void*));187/**188* [twalk(3)](http://man7.org/linux/man-pages/man3/twalk.3.html) calls189* `__visitor` on every node in the tree.190*/191void twalk(const void* __root, void (*__visitor)(const void*, VISIT, int)); // __INTRODUCED_IN(21);192__END_DECLS193194195