Add ability to change dontBroadcast status on hooked events (
bug 3886, r=ds).
2 * vim: set ts=4 sw=4 tw=99 noet :
3 * =============================================================================
5 * Copyright (C) 2004-2009 AlliedModders LLC. All rights reserved.
6 * =============================================================================
8 * This program is free software; you can redistribute it and/or modify it under
9 * the terms of the GNU General Public License, version 3.0, as published by the
10 * Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
17 * You should have received a copy of the GNU General Public License along with
18 * this program. If not, see <http://www.gnu.org/licenses/>.
20 * As a special exception, AlliedModders LLC gives you permission to link the
21 * code of this program (as well as its derivative works) to "Half-Life 2," the
22 * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
23 * by the Valve Corporation. You must obey the GNU General Public License in
24 * all respects for all other code used. Additionally, AlliedModders LLC grants
25 * this exception to all derivative works. AlliedModders LLC defines further
26 * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
27 * or <http://www.sourcemod.net/license.php>.
30 #ifndef _INCLUDE_SOURCEMOD_CORE_SYMBOLTABLE_H_
31 #define _INCLUDE_SOURCEMOD_CORE_SYMBOLTABLE_H_
37 #define KESTRING_TABLE_START_SIZE 65536
48 return reinterpret_cast<char *>(this + 1);
57 for (uint32_t i = 0; i < nbuckets; i++)
59 Symbol *sym = buckets[i];
62 Symbol *next = sym->tbl_next;
72 buckets = (Symbol **)malloc(sizeof(Symbol *) * KESTRING_TABLE_START_SIZE);
77 memset(buckets, 0, sizeof(Symbol *) * KESTRING_TABLE_START_SIZE);
79 nbuckets = KESTRING_TABLE_START_SIZE;
81 bucketmask = KESTRING_TABLE_START_SIZE - 1;
85 static inline uint32_t HashString(const char *data, size_t len)
88 #if (defined(__GNUC__) && defined(__i386__)) || defined(__WATCOMC__) \
89 || defined(_MSC_VER) || defined (__BORLANDC__) || defined (__TURBOC__)
90 #define get16bits(d) (*((const uint16_t *) (d)))
92 #if !defined (get16bits)
93 #define get16bits(d) ((((uint32_t)(((const uint8_t *)(d))[1])) << 8)\
94 +(uint32_t)(((const uint8_t *)(d))[0]) )
96 uint32_t hash = len, tmp;
99 if (len <= 0 || data == NULL)
108 for (;len > 0; len--) {
109 hash += get16bits (data);
110 tmp = (get16bits (data+2) << 11) ^ hash;
111 hash = (hash << 16) ^ tmp;
112 data += 2 * sizeof (uint16_t);
116 /* Handle end cases */
118 case 3: hash += get16bits (data);
120 hash ^= data[sizeof (uint16_t)] << 18;
123 case 2: hash += get16bits (data);
127 case 1: hash += *data;
132 /* Force "avalanching" of final 127 bits */
145 Symbol **FindSymbolBucket(const char *str, size_t len, uint32_t hash)
147 uint32_t bucket = hash & bucketmask;
148 Symbol **pkvs = &buckets[bucket];
153 if (len == kvs->length && memcmp(str, kvs->buffer(), len * sizeof(char)) == 0)
157 pkvs = &kvs->tbl_next;
164 void ResizeSymbolTable()
166 uint32_t xnbuckets = nbuckets * 2;
167 Symbol **xbuckets = (Symbol **)malloc(sizeof(Symbol *) * xnbuckets);
168 if (xbuckets == NULL)
172 memset(xbuckets, 0, sizeof(Symbol *) * xnbuckets);
173 uint32_t xbucketmask = xnbuckets - 1;
174 for (uint32_t i = 0; i < nbuckets; i++)
176 Symbol *sym = buckets[i];
179 Symbol *next = sym->tbl_next;
180 uint32_t bucket = sym->hash & xbucketmask;
181 sym->tbl_next = xbuckets[bucket];
182 xbuckets[bucket] = sym;
188 nbuckets = xnbuckets;
189 bucketmask = xbucketmask;
192 Symbol *FindSymbol(const char *str, size_t len)
194 uint32_t hash = HashString(str, len);
195 Symbol **pkvs = FindSymbolBucket(str, len, hash);
199 Symbol *InternSymbol(const char* str, size_t len, void *address)
201 uint32_t hash = HashString(str, len);
202 Symbol **pkvs = FindSymbolBucket(str, len, hash);
208 Symbol *kvs = (Symbol *)malloc(sizeof(Symbol) + sizeof(char) * (len + 1));
211 kvs->address = address;
212 kvs->tbl_next = NULL;
213 memcpy(kvs + 1, str, sizeof(char) * (len + 1));
217 if (nused > nbuckets && nbuckets <= INT_MAX / 2)
231 #endif //_INCLUDE_SOURCEMOD_CORE_SYMBOLTABLE_H_