1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
|
nodePool( int maxNodes , int hashSize ) :
m_nodes( 0 ) ,
m_first( 0 ) ,
m_next( 0 ) ,
m_maxNodes( maxNodes ) ,
m_hashSize( hashSize ) ,
m_nodeCount( 0 )
{
m_nodes = (dtNode*)alloc( sizeof( node )*m_maxNodes , ALLOC_PERM );
m_next = (nodeIndex*)alloc( sizeof( nodeIndex ) * m_maxNodes , ALLOC_PERM );
m_first = (nodeIndex*)alloc( sizeof( nodeIndex ) * hashSize , ALLOC_PERM );
memset( m_first , 0xff , sizeof( nodeIndex ) * m_hashSize );
memset( m_next , 0xff , sizeof( nodeIndex ) * m_maxNodes );
}
unsigned int hashRef( a )
{
a += ~( a << 15 );
a ^= ( a >> 10 );
a += ( a << 3 );
a ^= ( a >> 6 );
a += ~( a << 11 );
a ^= ( a >> 16 );
return (unsigned int)a;
}
findNode( id )
{
unsigned int bucket = hashRef( id ) & ( m_hashSize - 1 );
int i = m_first[bucket];
while( i != NULL )
{
if( m_nodes[i].id == id )
return &m_nodes[i];
i = m_next[i];
}
return 0;
} |