1 /* see copyright notice in squirrel.h */
\r
5 * The following code is based on Lua 4.0 (Copyright 1994-2002 Tecgraf, PUC-Rio.)
\r
6 * http://www.lua.org/copyright.html#4
\r
7 * http://www.lua.org/source/4.0.1/src_ltable.c.html
\r
10 #include "sqstring.h"
\r
12 #define hashptr(p) (((unsigned long)(p)) >> 3)
\r
14 struct SQTable : public SQDelegable
\r
23 _HashNode *_firstfree;
\r
28 ///////////////////////////
\r
29 void AllocNodes(int nSize);
\r
30 void Rehash(bool force);
\r
31 SQTable(SQSharedState *ss, int nInitialSize);
\r
33 static SQTable* Create(SQSharedState *ss,int nInitialSize)
\r
35 SQTable *newtable = (SQTable*)SQ_MALLOC(sizeof(SQTable));
\r
36 new (newtable) SQTable(ss, nInitialSize);
\r
37 newtable->_delegate = NULL;
\r
45 REMOVE_FROM_CHAIN(&_sharedstate->_gc_chain, this);
\r
46 for (int i = 0; i < _numofnodes; i++) _nodes[i].~_HashNode();
\r
47 SQ_FREE(_nodes, _numofnodes * sizeof(_HashNode));
\r
49 #ifndef NO_GARBAGE_COLLECTOR
\r
50 void Mark(SQCollectable **chain);
\r
52 inline unsigned long HashKey(const SQObjectPtr &key)
\r
55 case OT_STRING: return _string(key)->_hash;
\r
56 case OT_FLOAT: return (unsigned long)((long)_float(key));
\r
57 case OT_INTEGER: return (unsigned long)((long)_integer(key));
\r
58 default: return hashptr(key._unVal.pRefCounted);
\r
61 _HashNode *_Get(const SQObjectPtr &key,unsigned long hash)
\r
63 _HashNode *n = &_nodes[hash];
\r
65 if(_rawval(n->key) == _rawval(key) && type(n->key) == type(key)){
\r
68 }while(n = n->next);
\r
71 bool Get(const SQObjectPtr &key,SQObjectPtr &val);
\r
72 void Remove(const SQObjectPtr &key);
\r
73 bool Set(const SQObjectPtr &key, const SQObjectPtr &val);
\r
74 //returns true if a new slot has been created false if it was already present
\r
75 bool NewSlot(const SQObjectPtr &key,const SQObjectPtr &val);
\r
76 int Next(const SQObjectPtr &refpos, SQObjectPtr &outkey, SQObjectPtr &outval);
\r
81 sq_delete(this, SQTable);
\r
83 bool SetDelegate(SQTable *mt);
\r
88 #endif //_SQTABLE_H_
\r