src/libtess2/dict.h
Go to the documentation of this file.
00001 /*
00002 ** SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008) 
00003 ** Copyright (C) [dates of first publication] Silicon Graphics, Inc.
00004 ** All Rights Reserved.
00005 **
00006 ** Permission is hereby granted, free of charge, to any person obtaining a copy
00007 ** of this software and associated documentation files (the "Software"), to deal
00008 ** in the Software without restriction, including without limitation the rights
00009 ** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
00010 ** of the Software, and to permit persons to whom the Software is furnished to do so,
00011 ** subject to the following conditions:
00012 ** 
00013 ** The above copyright notice including the dates of first publication and either this
00014 ** permission notice or a reference to http://oss.sgi.com/projects/FreeB/ shall be
00015 ** included in all copies or substantial portions of the Software. 
00016 **
00017 ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
00018 ** INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
00019 ** PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL SILICON GRAPHICS, INC.
00020 ** BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
00021 ** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
00022 ** OR OTHER DEALINGS IN THE SOFTWARE.
00023 ** 
00024 ** Except as contained in this notice, the name of Silicon Graphics, Inc. shall not
00025 ** be used in advertising or otherwise to promote the sale, use or other dealings in
00026 ** this Software without prior written authorization from Silicon Graphics, Inc.
00027 */
00028 /*
00029 ** Author: Eric Veach, July 1994.
00030 */
00031 
00032 #ifndef DICT_LIST_H
00033 #define DICT_LIST_H
00034 
00035 typedef void *DictKey;
00036 typedef struct Dict Dict;
00037 typedef struct DictNode DictNode;
00038 
00039 Dict *dictNewDict( TESSalloc* alloc, void *frame, int (*leq)(void *frame, DictKey key1, DictKey key2) );
00040 
00041 void dictDeleteDict( TESSalloc* alloc, Dict *dict );
00042 
00043 /* Search returns the node with the smallest key greater than or equal
00044 * to the given key.  If there is no such key, returns a node whose
00045 * key is NULL.  Similarly, Succ(Max(d)) has a NULL key, etc.
00046 */
00047 DictNode *dictSearch( Dict *dict, DictKey key );
00048 DictNode *dictInsertBefore( Dict *dict, DictNode *node, DictKey key );
00049 void dictDelete( Dict *dict, DictNode *node );
00050 
00051 #define dictKey(n)  ((n)->key)
00052 #define dictSucc(n) ((n)->next)
00053 #define dictPred(n) ((n)->prev)
00054 #define dictMin(d)  ((d)->head.next)
00055 #define dictMax(d)  ((d)->head.prev)
00056 #define dictInsert(d,k) (dictInsertBefore((d),&(d)->head,(k)))
00057 
00058 
00059 /*** Private data structures ***/
00060 
00061 struct DictNode {
00062     DictKey key;
00063     DictNode *next;
00064     DictNode *prev;
00065 };
00066 
00067 struct Dict {
00068     DictNode head;
00069     void *frame;
00070     struct BucketAlloc *nodePool;
00071     int (*leq)(void *frame, DictKey key1, DictKey key2);
00072 };
00073 
00074 #endif