# HG changeset patch # User tkaito # Date 1295347981 -32400 # Node ID ee481853d5dda1c8b70968cb67f9d93ab1316892 # Parent d2d44bc55fa1bb3c00778020ea1ebbab7ffbb7c3 SgidHash remove. diff -r d2d44bc55fa1 -r ee481853d5dd Renderer/Engine/SceneGraphRoot.cc --- a/Renderer/Engine/SceneGraphRoot.cc Tue Jan 18 18:53:23 2011 +0900 +++ b/Renderer/Engine/SceneGraphRoot.cc Tue Jan 18 19:53:01 2011 +0900 @@ -7,14 +7,14 @@ #include "TextureHash.h" #include "texture.h" #include "Application.h" -#include "SgidHash.h" static int cnt = 0; static const int SGLIST_LENGTH = 138; static int sg_src_size = SGLIST_LENGTH ; static int sg_src_id = -1; static SceneGraphPtr *sg_src; -static SgidHash sgid_hash; + +static TextureHash sgid_hash; SceneGraphRoot *sgroot; @@ -114,7 +114,7 @@ } sg->sgid = ++sg_src_id; sg_src[sg->sgid] = sg; - sgid_hash.hash_regist((const char*)sg->name, sg->sgid); + sgid_hash.sg_hash_regist((const char*)sg->name, sg->sgid); } diff -r d2d44bc55fa1 -r ee481853d5dd Renderer/Engine/SgidHash.cc --- a/Renderer/Engine/SgidHash.cc Tue Jan 18 18:53:23 2011 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,72 +0,0 @@ -#include -#include -#include -#include "SgidHash.h" - -SgidHash::SgidHash(void) -{ - int size = sizeof(sg_hashtable)*SGID_NUM; -#if defined(__SPU__) || ! defined(HAS_POSIX_MEMALIGN) - table = (sg_hashtable*)malloc(size); -#else - posix_memalign((void**)&table, alignment, size); -#endif - for (int i = 0; i < SGID_NUM; i++) { - table[i].sg_id = -1; - table[i].key = NULL; - } -} - -SgidHash::~SgidHash(void) -{ - free(table); -} - -int -SgidHash::hash_function(const char *key) -{ - //float value = 0.0; - int value = 0; - - for (int i = 0; key[i]; i++) { - value += key[i]*(i+1)*17+1; - } - - return value%SGID_NUM; -} - -int -SgidHash::hash_regist(const char* key, int &id) -{ - int hash = hash_function(key); - - for (int i = 0; ; i++) { - if (table[hash].sg_id == -1) { - table[hash].key = (char*)key; - table[hash].sg_id = id; - return 0; - - } else if (strcmp(key, table[hash].key) == 0 - && table[hash].sg_id != -1){ - return table[hash].sg_id; - } - hash = ((37*hash)^(11*i)) % SGID_NUM; - } -} - -int -SgidHash::get_sgid(const char* key) -{ - - int hash = hash_function(key); - for (int i = 0; ; i++) { - if (table[hash].sg_id == -1) { - return -1; - - } else if (strcmp(key, table[hash].key) == 0 - && table[hash].sg_id != -1){ - return table[hash].sg_id; - } - hash = ((37*hash)^(11*i)) % SGID_NUM; - } -} diff -r d2d44bc55fa1 -r ee481853d5dd Renderer/Engine/SgidHash.h --- a/Renderer/Engine/SgidHash.h Tue Jan 18 18:53:23 2011 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,23 +0,0 @@ -#ifndef INCLUDED_SGID_HASH -#define INCLUDED_SGID_HASH - -const int SGID_NUM = 1000; - -struct sg_hashtable{ - int sg_id; - char* key; -}; - -class SgidHash{ -public: - sg_hashtable *table; - - SgidHash(void); - ~SgidHash(void); - int hash_function(const char* image_name); - int hash_regist(const char* image_name, int &sg_id); - int get_sgid(const char* key); - void remove(int id) { table[id].sg_id = -1; } -}; - -#endif diff -r d2d44bc55fa1 -r ee481853d5dd Renderer/Engine/TextureHash.cc --- a/Renderer/Engine/TextureHash.cc Tue Jan 18 18:53:23 2011 +0900 +++ b/Renderer/Engine/TextureHash.cc Tue Jan 18 19:53:01 2011 +0900 @@ -7,6 +7,7 @@ TextureHash::TextureHash(void) { int size = sizeof(hashtable)*TABLE_SIZE; + #if defined(__SPU__) || ! defined(HAS_POSIX_MEMALIGN) table = (hashtable*)malloc(size); #else @@ -39,19 +40,54 @@ int TextureHash::hash_regist(const char* key, int &id) { + int hash = hash_function(key); + for (int i = 0; ; i++) { + if (table[hash].tx_id == -1) { + table[hash].key = (char*)key; + id = id_count++; + return 0; + + } else if (strcmp(key, table[hash].key) == 0 + && table[hash].tx_id != -1){ + id = table[hash].tx_id; + return 1; + } + hash = ((37*hash)^(11*i)) % TABLE_SIZE; + } +} + +int +TextureHash::sg_hash_regist(const char* key, int &id) +{ int hash = hash_function(key); for (int i = 0; ; i++) { if (table[hash].tx_id == -1) { table[hash].key = (char*)key; - id = id_count++; + table[hash].tx_id = id; return 0; } else if (strcmp(key, table[hash].key) == 0 && table[hash].tx_id != -1){ - id = table[hash].tx_id; - return 1; + return table[hash].tx_id; } hash = ((37*hash)^(11*i)) % TABLE_SIZE; } } + +int +TextureHash::get_sgid(const char* key) +{ + + int hash = hash_function(key); + for (int i = 0; ; i++) { + if (table[hash].tx_id == -1) { + return -1; + + } else if (strcmp(key, table[hash].key) == 0 + && table[hash].tx_id != -1){ + return table[hash].tx_id; + } + hash = ((37*hash)^(11*i)) % TABLE_SIZE; + } +} diff -r d2d44bc55fa1 -r ee481853d5dd Renderer/Engine/TextureHash.h --- a/Renderer/Engine/TextureHash.h Tue Jan 18 18:53:23 2011 +0900 +++ b/Renderer/Engine/TextureHash.h Tue Jan 18 19:53:01 2011 +0900 @@ -1,7 +1,7 @@ #ifndef INCLUDED_TEXTURE_HASH #define INCLUDED_TEXTURE_HASH -const int TABLE_SIZE = 8192; +const int TABLE_SIZE = 9192; //8192 + 1000 struct hashtable{ int tx_id; @@ -16,6 +16,8 @@ ~TextureHash(void); int hash_function(const char* image_name); int hash_regist(const char* image_name, int &tx_id); + int sg_hash_regist(const char* image_name, int &tx_id); + int get_sgid(const char* key); void remove(int id) { table[id].tx_id = -1; } };