2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
6 * These libraries and programs are free software; you can
7 * redistribute them and/or modify them under the terms of the GNU
8 * Lesser General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
12 * These libraries and programs are distributed in the hope that
13 * they will be useful, but WITHOUT ANY WARRANTY; without even the
14 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU Lesser General Public License for more
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these librararies and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
23 /* $XConsortium: AttributeStore.C /main/3 1996/08/21 15:46:08 drk $ */
31 #include "AttributeRec.h"
32 #include "AttributeStore.h"
33 #include "HashBucketEntry.h"
37 #define DBG(level) if ( dbgLevel >= level)
39 #define DBG(level) if (0)
42 //---------------------------------------------------------
43 // AttributeStore : Constructor
45 AttributeStore::AttributeStore( int sz ):NumBuckets(sz)
49 dbgStr = getenv("OL_DEBUG");
50 dbgLevel = ( dbgStr ? atoi(dbgStr):0);
52 HashTable = new HashBucketEntry * [ NumBuckets ];
54 cerr << "(ERROR) Unable to allocate memory for HashTable\n";
58 for ( int i=0; i < sz; i++) {
64 //---------------------------------------------------------
65 // AttributeStore : Destructor
67 AttributeStore::~AttributeStore()
69 for ( int i=0; i < NumBuckets; i++ ) {
74 //---------------------------------------------------------
75 // AttributeStore::hash()
76 int AttributeStore::hash( char *HashKeyStr )
78 DBG(10) cerr << "(DEBUG) Invoking hash function with HashKeyStr = "
79 << HashKeyStr << endl;
83 // This is a simple hash function
84 for ( char *ptr=HashKeyStr; *ptr; ptr++ ) {
88 sum = sum % NumBuckets;
90 DBG(10) cerr << "(DEBUG) returning value for hash function = "
96 //---------------------------------------------------------
97 // AttributeStore::lookup
98 char *AttributeStore::lookup( Token *ThisToken, char *aName )
101 AttributeRec *aRecPtr;
103 HashValue=hash( aName );
104 aRecPtr = HashTable[ HashValue ]->lookup( aName );
106 return ( aRecPtr->GetAttributeValue( ThisToken ) );
109 //---------------------------------------------------------
110 // AttributeStore::add
112 int AttributeStore::insert ( AttributeRec *att )
116 HashBucketEntry *BucketEntry;
118 HashValue = hash ( att->name );
120 BucketEntry = HashTable [ HashValue ];
122 if ( BucketEntry->lookup ( att->name ) ) {
126 BucketEntry->insert( att );