dthdr.h revision 3f54fd611f536639ec30dd53c48e5ec1897cc7d9
01aafb6a9520f05df5ff467b591ecb5474dcfc86Christian Maeder/***********************************************************************
01aafb6a9520f05df5ff467b591ecb5474dcfc86Christian Maeder* *
e6d40133bc9f858308654afb1262b8b483ec5922Till Mossakowski* This software is part of the BSD package *
1549f3abf73c1122acff724f718b615c82fa3648Till Mossakowski*Copyright (c) 1978-2002 The Regents of the University of California an*
97018cf5fa25b494adffd7e9b4e87320dae6bf47Christian Maeder* *
01aafb6a9520f05df5ff467b591ecb5474dcfc86Christian Maeder* Redistribution and use in source and binary forms, with or *
b4fbc96e05117839ca409f5f20f97b3ac872d1edTill Mossakowski* without modification, are permitted provided that the following *
01aafb6a9520f05df5ff467b591ecb5474dcfc86Christian Maeder* conditions are met: *
01aafb6a9520f05df5ff467b591ecb5474dcfc86Christian Maeder* *
f3a94a197960e548ecd6520bb768cb0d547457bbChristian Maeder* 1. Redistributions of source code must retain the above *
e6d40133bc9f858308654afb1262b8b483ec5922Till Mossakowski* copyright notice, this list of conditions and the *
1549f3abf73c1122acff724f718b615c82fa3648Till Mossakowski* following disclaimer. *
01aafb6a9520f05df5ff467b591ecb5474dcfc86Christian Maeder* *
1549f3abf73c1122acff724f718b615c82fa3648Till Mossakowski* 2. Redistributions in binary form must reproduce the above *
1549f3abf73c1122acff724f718b615c82fa3648Till Mossakowski* copyright notice, this list of conditions and the *
1549f3abf73c1122acff724f718b615c82fa3648Till Mossakowski* following disclaimer in the documentation and/or other *
1549f3abf73c1122acff724f718b615c82fa3648Till Mossakowski* materials provided with the distribution. *
a001917177db7ae636853b37c0d0f9f4e90a83ffChristian Maeder* *
a001917177db7ae636853b37c0d0f9f4e90a83ffChristian Maeder* 3. Neither the name of The Regents of the University of California*
01aafb6a9520f05df5ff467b591ecb5474dcfc86Christian Maeder* names of its contributors may be used to endorse or *
01aafb6a9520f05df5ff467b591ecb5474dcfc86Christian Maeder* promote products derived from this software without *
01aafb6a9520f05df5ff467b591ecb5474dcfc86Christian Maeder* specific prior written permission. *
01aafb6a9520f05df5ff467b591ecb5474dcfc86Christian Maeder* *
f8b715ab2993083761c0aedb78f1819bcf67b6ccChristian Maeder* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND *
01aafb6a9520f05df5ff467b591ecb5474dcfc86Christian Maeder* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, *
575a55eadc8dcab8ee350324b417cbd9e52e69c0Christian Maeder* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF *
ad270004874ce1d0697fb30d7309f180553bb315Christian Maeder* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE *
ad270004874ce1d0697fb30d7309f180553bb315Christian Maeder* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS *
5e46b572ed576c0494768998b043d9d340594122Till Mossakowski* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
db453fe9625a9dab5d108f7a5e464598814144b8Jian Chun Wang* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED *
23a00c966f2aa8da525d7a7c51933c99964426c0Christian Maeder* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, *
575a55eadc8dcab8ee350324b417cbd9e52e69c0Christian Maeder* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON *
575a55eadc8dcab8ee350324b417cbd9e52e69c0Christian Maeder* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, *
575a55eadc8dcab8ee350324b417cbd9e52e69c0Christian Maeder* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY *
db453fe9625a9dab5d108f7a5e464598814144b8Jian Chun Wang* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE *
575a55eadc8dcab8ee350324b417cbd9e52e69c0Christian Maeder* POSSIBILITY OF SUCH DAMAGE. *
575a55eadc8dcab8ee350324b417cbd9e52e69c0Christian Maeder* *
a001917177db7ae636853b37c0d0f9f4e90a83ffChristian Maeder* Redistribution and use in source and binary forms, with or without *
a001917177db7ae636853b37c0d0f9f4e90a83ffChristian Maeder* modification, are permitted provided that the following conditions *
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski* are met: *
01aafb6a9520f05df5ff467b591ecb5474dcfc86Christian Maeder* 1. Redistributions of source code must retain the above copyright *
0e2ae85e2453466d03c1fc5884a3d693235bb9d9Christian Maeder* notice, this list of conditions and the following disclaimer. *
01aafb6a9520f05df5ff467b591ecb5474dcfc86Christian Maeder* 2. Redistributions in binary form must reproduce the above copyright *
ca020e82eb3567e7bdbb1cf70729efbd07e9caa4Klaus Luettich* notice, this list of conditions and the following disclaimer in *
c438c79d00fc438f99627e612498744bdc0d0c89Christian Maeder* the documentation and/or other materials provided with the *
ca020e82eb3567e7bdbb1cf70729efbd07e9caa4Klaus Luettich* distribution. *
ca020e82eb3567e7bdbb1cf70729efbd07e9caa4Klaus Luettich* 3. Neither the name of the University nor the names of its *
ca020e82eb3567e7bdbb1cf70729efbd07e9caa4Klaus Luettich* contributors may be used to endorse or promote products derived *
ca020e82eb3567e7bdbb1cf70729efbd07e9caa4Klaus Luettich* from this software without specific prior written permission. *
ca020e82eb3567e7bdbb1cf70729efbd07e9caa4Klaus Luettich* *
a001917177db7ae636853b37c0d0f9f4e90a83ffChristian Maeder* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS" *
a001917177db7ae636853b37c0d0f9f4e90a83ffChristian Maeder* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
01aafb6a9520f05df5ff467b591ecb5474dcfc86Christian Maeder* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS *
01aafb6a9520f05df5ff467b591ecb5474dcfc86Christian Maeder* OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, *
01aafb6a9520f05df5ff467b591ecb5474dcfc86Christian Maeder* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT *
4b6aa93c12e4db86ccc7694a48a73e9cf7262d06Christian Maeder* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF *
a001917177db7ae636853b37c0d0f9f4e90a83ffChristian Maeder* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND *
b10d6cef708b7a659f2d3b367e8e0db0d03ae3f5Till Mossakowski* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, *
b10d6cef708b7a659f2d3b367e8e0db0d03ae3f5Till Mossakowski* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT *
01aafb6a9520f05df5ff467b591ecb5474dcfc86Christian Maeder* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF *
8e80792f474d154ff11762fac081a422e34f1accChristian Maeder* SUCH DAMAGE. *
26d11a256b1433604a3dbc69913b520fff7586acChristian Maeder* *
26d11a256b1433604a3dbc69913b520fff7586acChristian Maeder* Kurt Shoens (UCB) *
26d11a256b1433604a3dbc69913b520fff7586acChristian Maeder* gsf *
26d11a256b1433604a3dbc69913b520fff7586acChristian Maeder* *
26d11a256b1433604a3dbc69913b520fff7586acChristian Maeder***********************************************************************/
26d11a256b1433604a3dbc69913b520fff7586acChristian Maeder#ifndef _DTHDR_H
26d11a256b1433604a3dbc69913b520fff7586acChristian Maeder#define _DTHDR_H 1
01aafb6a9520f05df5ff467b591ecb5474dcfc86Christian Maeder#define _KPV_ONLY 1
4b6aa93c12e4db86ccc7694a48a73e9cf7262d06Christian Maeder
4b6aa93c12e4db86ccc7694a48a73e9cf7262d06Christian Maeder/* Internal definitions for libcdt.
4b6aa93c12e4db86ccc7694a48a73e9cf7262d06Christian Maeder** Written by Kiem-Phong Vo (07/15/95)
4b6aa93c12e4db86ccc7694a48a73e9cf7262d06Christian Maeder*/
a001917177db7ae636853b37c0d0f9f4e90a83ffChristian Maeder
4fc727afa544a757d1959ce77c02208f8bf330dcChristian Maeder#include "cdt.h"
0e2ae85e2453466d03c1fc5884a3d693235bb9d9Christian Maeder
4b6aa93c12e4db86ccc7694a48a73e9cf7262d06Christian Maeder/* short-hand notations */
5e46b572ed576c0494768998b043d9d340594122Till Mossakowski#define reg register
5e46b572ed576c0494768998b043d9d340594122Till Mossakowski#define ulong unsigned long
5e46b572ed576c0494768998b043d9d340594122Till Mossakowski#define left hl._left
4b6aa93c12e4db86ccc7694a48a73e9cf7262d06Christian Maeder#define hash hl._hash
4b6aa93c12e4db86ccc7694a48a73e9cf7262d06Christian Maeder#define htab hh._htab
4b6aa93c12e4db86ccc7694a48a73e9cf7262d06Christian Maeder#define head hh._head
4b6aa93c12e4db86ccc7694a48a73e9cf7262d06Christian Maeder
7a47fbe6b987bd69a5056ce5d00fc8710f6c5e8aChristian Maeder/* this must be disjoint from DT_METHODS */
a001917177db7ae636853b37c0d0f9f4e90a83ffChristian Maeder#define DT_FLATTEN 010000 /* dictionary already flattened */
e01299e9b22b96b31b720ca1e9f9f5f25af9b024Christian Maeder
a001917177db7ae636853b37c0d0f9f4e90a83ffChristian Maeder/* bits used for secondary hashing */
e01299e9b22b96b31b720ca1e9f9f5f25af9b024Christian Maeder#define HIGHBIT (~(((ulong)~0L) >> 1))
7a47fbe6b987bd69a5056ce5d00fc8710f6c5e8aChristian Maeder#define SETVISIT(h) ((h) | HIGHBIT)
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski#define CLRVISIT(h) ((h) & ~HIGHBIT)
a001917177db7ae636853b37c0d0f9f4e90a83ffChristian Maeder#define ISVISIT(h) ((h) & HIGHBIT)
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski#define REHASH(h) (((h)<<5) - (h))
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski/* hash start size and load factor */
4b6aa93c12e4db86ccc7694a48a73e9cf7262d06Christian Maeder#define HSLOT (32)
a001917177db7ae636853b37c0d0f9f4e90a83ffChristian Maeder#define HRESIZE(n) ((n) << 1)
4fc727afa544a757d1959ce77c02208f8bf330dcChristian Maeder#define HLOAD(s) ((s) << 1)
4b6aa93c12e4db86ccc7694a48a73e9cf7262d06Christian Maeder#define HINDEX(n,h) ((h)&((n)-1))
7a47fbe6b987bd69a5056ce5d00fc8710f6c5e8aChristian Maeder
a001917177db7ae636853b37c0d0f9f4e90a83ffChristian Maeder#define UNFLATTEN(dt) \
68138d26bcddf5e89c30206aa83ab5ec006d170dChristian Maeder ((dt->data->type&DT_FLATTEN) ? dtrestore(dt,NIL(Dtlink_t*)) : 0)
4601edb679f0ba530bbb085b25d82a411cd070aaChristian Maeder
4601edb679f0ba530bbb085b25d82a411cd070aaChristian Maeder/* the pointer to the actual object */
4601edb679f0ba530bbb085b25d82a411cd070aaChristian Maeder#define ELT(o,d) ((Dtlink_t*)((char*)(o) + d->link) )
4601edb679f0ba530bbb085b25d82a411cd070aaChristian Maeder#define OBJ(e,d) (d->link == 0 ? (Void_t*)(e) : \
26d11a256b1433604a3dbc69913b520fff7586acChristian Maeder d->link < 0 ? ((Dthold_t*)(e))->obj : \
a001917177db7ae636853b37c0d0f9f4e90a83ffChristian Maeder (Void_t*)((char*)(e) - d->link) )
01aafb6a9520f05df5ff467b591ecb5474dcfc86Christian Maeder#define KEY(o,d) (d->size < 0 ? *((char**)((char*)(o) + d->key)) : \
e01299e9b22b96b31b720ca1e9f9f5f25af9b024Christian Maeder ((char*)(o) + d->key) )
e01299e9b22b96b31b720ca1e9f9f5f25af9b024Christian Maeder
e01299e9b22b96b31b720ca1e9f9f5f25af9b024Christian Maeder/* compare function */
4601edb679f0ba530bbb085b25d82a411cd070aaChristian Maeder#define CMP(dt,k1,k2,d) (d->comparf ? (*d->comparf)(dt,k1,k2,d) : \
01aafb6a9520f05df5ff467b591ecb5474dcfc86Christian Maeder d->size <= 0 ? strcmp(k1,k2) : memcmp(k1,k2,d->size) )
01aafb6a9520f05df5ff467b591ecb5474dcfc86Christian Maeder
01aafb6a9520f05df5ff467b591ecb5474dcfc86Christian Maeder/* hash function */
01aafb6a9520f05df5ff467b591ecb5474dcfc86Christian Maeder#define HASH(dt,k,d) (d->hashf ? (*d->hashf)(dt,k,d) : dtstrhash(0,k,d->size) )
01aafb6a9520f05df5ff467b591ecb5474dcfc86Christian Maeder
01aafb6a9520f05df5ff467b591ecb5474dcfc86Christian Maeder/* tree rotation functions */
01aafb6a9520f05df5ff467b591ecb5474dcfc86Christian Maeder#define RROTATE(x,y) ((x)->left = (y)->right, (y)->right = (x), (x) = (y))
01aafb6a9520f05df5ff467b591ecb5474dcfc86Christian Maeder#define LROTATE(x,y) ((x)->right = (y)->left, (y)->left = (x), (x) = (y))
01aafb6a9520f05df5ff467b591ecb5474dcfc86Christian Maeder#define RLINK(r,x) (r = r->left = x )
01aafb6a9520f05df5ff467b591ecb5474dcfc86Christian Maeder#define LLINK(l,x) (l = l->right = x )
01aafb6a9520f05df5ff467b591ecb5474dcfc86Christian Maeder
01aafb6a9520f05df5ff467b591ecb5474dcfc86Christian Maeder_BEGIN_EXTERNS_
01aafb6a9520f05df5ff467b591ecb5474dcfc86Christian Maeder
01aafb6a9520f05df5ff467b591ecb5474dcfc86Christian Maeder#if defined(extern)
01aafb6a9520f05df5ff467b591ecb5474dcfc86Christian Maeder#undef extern
01aafb6a9520f05df5ff467b591ecb5474dcfc86Christian Maeder#endif
01aafb6a9520f05df5ff467b591ecb5474dcfc86Christian Maeder#if !_PACKAGE_ast && _BLD_DLL && defined(_WIN32)
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski#define extern __declspec(dllimport)
01aafb6a9520f05df5ff467b591ecb5474dcfc86Christian Maeder#endif
01aafb6a9520f05df5ff467b591ecb5474dcfc86Christian Maeder
01aafb6a9520f05df5ff467b591ecb5474dcfc86Christian Maeder#if !_PACKAGE_ast
01aafb6a9520f05df5ff467b591ecb5474dcfc86Christian Maederextern Void_t* malloc _ARG_((int));
7a47fbe6b987bd69a5056ce5d00fc8710f6c5e8aChristian Maederextern void free _ARG_((Void_t*));
5e46b572ed576c0494768998b043d9d340594122Till Mossakowskiextern int memcmp _ARG_((const Void_t*, const Void_t*, size_t));
612749008484b6773aedf4d6bbc85b8d074d15c6Christian Maederextern int strcmp _ARG_((const char*, const char*));
612749008484b6773aedf4d6bbc85b8d074d15c6Christian Maeder#endif
5e46b572ed576c0494768998b043d9d340594122Till Mossakowski
1f086d5155f47fdad9a0de4e46bbebb2c4b33d30Christian Maeder#if defined(extern)
a001917177db7ae636853b37c0d0f9f4e90a83ffChristian Maeder#undef extern
88ece6e49930670e8fd3ee79c89a2e918d2fbd0cChristian Maeder#endif
a001917177db7ae636853b37c0d0f9f4e90a83ffChristian Maeder#if _PACKAGE_ast && defined(__EXPORT__)
a001917177db7ae636853b37c0d0f9f4e90a83ffChristian Maeder#define extern __EXPORT__
a001917177db7ae636853b37c0d0f9f4e90a83ffChristian Maeder#endif
0e2ae85e2453466d03c1fc5884a3d693235bb9d9Christian Maeder
a001917177db7ae636853b37c0d0f9f4e90a83ffChristian Maeder_END_EXTERNS_
a001917177db7ae636853b37c0d0f9f4e90a83ffChristian Maeder
a001917177db7ae636853b37c0d0f9f4e90a83ffChristian Maeder#endif /* _DTHDR_H */
0e2ae85e2453466d03c1fc5884a3d693235bb9d9Christian Maeder