Mercurial > hg > Members > kono > Cerium
diff Renderer/Engine/spe/TileHash.cc @ 507:735f76483bb2
Reorganization..
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Mon, 12 Oct 2009 09:39:35 +0900 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Renderer/Engine/spe/TileHash.cc Mon Oct 12 09:39:35 2009 +0900 @@ -0,0 +1,94 @@ +#include <stdio.h> +#include <string.h> +#include <stdlib.h> +#include "TileHash.h" + +#if 0 + +not used now + +static unsigned short PRIME[8] = { + 0x002, 0x065, 0x0c7, 0x133, 0x191, 0x1f3, 0x259, 0x2bd, +}; + +int +TileHash::hash(memaddr data) +{ + int value = 0; + int n = 0; + int key; + + for (uint32 i = 0; i < sizeof(memaddr) * 2; i ++) { + key = data & 0xf; + value += key * PRIME[n++ & 7]; + data >>= 4; + } + + return value % hashSize; +} + +TileHash::TileHash(void) +{ + //hashSize = 263; + //tableSize = sizeof(TilePtr)*hashSize; + + table = (TilePtr*)malloc(tableSize); + clear(); +} + +int +TileHash::put(memaddr key, TilePtr data) +{ + int hashval = hash(key); + + for (int i = 0; i < hashSize/2; i++) { + int index = (hashval + i*i)%hashSize; + + if (table[index] == 0) { // 空の table に入れる + table[index] = data; + return index; + } + } + + return -1; +} + +TilePtr +TileHash::get(memaddr key) +{ + int hashval = hash(key); + + for (int i = 0; i < hashSize/2; i++) { + int index = (hashval + i*i)%hashSize; + + if (table[index] != NULL && + table[index]->address == key) { + return table[index]; + } + } + + return NULL; +} + +void +TileHash::remove(memaddr key) +{ + int hashval = hash(key); + + for (int i = 0; i < hashSize/2; i++) { + int index = (hashval + i*i)%hashSize; + + if (table[index] != NULL && + table[index]->address == key) { + table[index] = NULL; + } + } +} + +void +TileHash::clear(void) +{ + bzero(table, tableSize); +} +#endif +