Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
dict.c
Go to the documentation of this file.
1/*
2 * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
3 * Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice including the dates of first publication and
13 * either this permission notice or a reference to
14 * http://oss.sgi.com/projects/FreeB/
15 * shall be included in all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
22 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 * SOFTWARE.
24 *
25 * Except as contained in this notice, the name of Silicon Graphics, Inc.
26 * shall not be used in advertising or otherwise to promote the sale, use or
27 * other dealings in this Software without prior written authorization from
28 * Silicon Graphics, Inc.
29 */
30/*
31** Author: Eric Veach, July 1994.
32**
33*/
34
35#include <stddef.h>
36#include "dict-list.h"
37#include "memalloc.h"
38
39/* really __gl_dictListNewDict */
40Dict *dictNewDict( void *frame,
41 int (*leq)(void *frame, DictKey key1, DictKey key2) )
42{
43 Dict *dict = (Dict *) memAlloc( sizeof( Dict ));
44 DictNode *head;
45
46 if (dict == NULL) return NULL;
47
48 head = &dict->head;
49
50 head->key = NULL;
51 head->next = head;
52 head->prev = head;
53
54 dict->frame = frame;
55 dict->leq = leq;
56
57 return dict;
58}
59
60/* really __gl_dictListDeleteDict */
61void dictDeleteDict( Dict *dict )
62{
63 DictNode *node, *next;
64
65 for( node = dict->head.next; node != &dict->head; node = next ) {
66 next = node->next;
67 memFree( node );
68 }
69 memFree( dict );
70}
71
72/* really __gl_dictListInsertBefore */
74{
75 DictNode *newNode;
76
77 do {
78 node = node->prev;
79 } while( node->key != NULL && ! (*dict->leq)(dict->frame, node->key, key));
80
81 newNode = (DictNode *) memAlloc( sizeof( DictNode ));
82 if (newNode == NULL) return NULL;
83
84 newNode->key = key;
85 newNode->next = node->next;
86 node->next->prev = newNode;
87 newNode->prev = node;
88 node->next = newNode;
89
90 return newNode;
91}
92
93/* really __gl_dictListDelete */
94void dictDelete( Dict *dict, DictNode *node ) /*ARGSUSED*/
95{
96 (void)dict;
97 node->next->prev = node->prev;
98 node->prev->next = node->next;
99 memFree( node );
100}
101
102/* really __gl_dictListSearch */
104{
105 DictNode *node = &dict->head;
106
107 do {
108 node = node->next;
109 } while( node->key != NULL && ! (*dict->leq)(dict->frame, key, node->key));
110
111 return node;
112}
typedef void(GLAPIENTRYP _GLUfuncptr)(void)
#define dictDeleteDict(dict)
Definition dict-list.h:45
#define dictSearch(dict, key)
Definition dict-list.h:47
#define dictDelete(dict, node)
Definition dict-list.h:50
#define dictInsertBefore(dict, node, key)
Definition dict-list.h:49
#define dictNewDict(frame, leq)
Definition dict-list.h:44
void * DictKey
Definition dict-list.h:60
#define memAlloc
Definition memalloc.h:48
#define memFree
Definition memalloc.h:41
DictNode * prev
Definition dict-list.h:91
DictKey key
Definition dict-list.h:89
DictNode * next
Definition dict-list.h:90
DictNode head
Definition dict-list.h:95
int(* leq)(void *frame, DictKey key1, DictKey key2)
Definition dict-list.h:97
void * frame
Definition dict-list.h:96