annotate TaskManager/Test/test_render/spe/TileHash.cpp @ 380:b4b8345b5366

ps3 fix
author e065701@localhost.localdomain
date Fri, 31 Jul 2009 20:44:08 +0900
parents 3f5289873643
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
184
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents: 173
diff changeset
1 #include <stdio.h>
167
c8b868871dce DrawSpan で使う Tile の Hash の扱いは class TileHash を生成する事に。
gongo@localhost.localdomain
parents:
diff changeset
2 #include <string.h>
c8b868871dce DrawSpan で使う Tile の Hash の扱いは class TileHash を生成する事に。
gongo@localhost.localdomain
parents:
diff changeset
3 #include <stdlib.h>
c8b868871dce DrawSpan で使う Tile の Hash の扱いは class TileHash を生成する事に。
gongo@localhost.localdomain
parents:
diff changeset
4 #include "TileHash.h"
c8b868871dce DrawSpan で使う Tile の Hash の扱いは class TileHash を生成する事に。
gongo@localhost.localdomain
parents:
diff changeset
5
c8b868871dce DrawSpan で使う Tile の Hash の扱いは class TileHash を生成する事に。
gongo@localhost.localdomain
parents:
diff changeset
6 static unsigned short PRIME[8] = {
c8b868871dce DrawSpan で使う Tile の Hash の扱いは class TileHash を生成する事に。
gongo@localhost.localdomain
parents:
diff changeset
7 0x002, 0x065, 0x0c7, 0x133, 0x191, 0x1f3, 0x259, 0x2bd,
c8b868871dce DrawSpan で使う Tile の Hash の扱いは class TileHash を生成する事に。
gongo@localhost.localdomain
parents:
diff changeset
8 };
c8b868871dce DrawSpan で使う Tile の Hash の扱いは class TileHash を生成する事に。
gongo@localhost.localdomain
parents:
diff changeset
9
c8b868871dce DrawSpan で使う Tile の Hash の扱いは class TileHash を生成する事に。
gongo@localhost.localdomain
parents:
diff changeset
10 int
380
b4b8345b5366 ps3 fix
e065701@localhost.localdomain
parents: 352
diff changeset
11 TileHash::hash(memaddr data)
167
c8b868871dce DrawSpan で使う Tile の Hash の扱いは class TileHash を生成する事に。
gongo@localhost.localdomain
parents:
diff changeset
12 {
c8b868871dce DrawSpan で使う Tile の Hash の扱いは class TileHash を生成する事に。
gongo@localhost.localdomain
parents:
diff changeset
13 int value = 0;
c8b868871dce DrawSpan で使う Tile の Hash の扱いは class TileHash を生成する事に。
gongo@localhost.localdomain
parents:
diff changeset
14 int n = 0;
c8b868871dce DrawSpan で使う Tile の Hash の扱いは class TileHash を生成する事に。
gongo@localhost.localdomain
parents:
diff changeset
15 int key;
c8b868871dce DrawSpan で使う Tile の Hash の扱いは class TileHash を生成する事に。
gongo@localhost.localdomain
parents:
diff changeset
16
380
b4b8345b5366 ps3 fix
e065701@localhost.localdomain
parents: 352
diff changeset
17 for (uint32 i = 0; i < sizeof(memaddr) * 2; i ++) {
352
3f5289873643 add global_alloc.h
admin@mb22-no-macbook-2.local
parents: 210
diff changeset
18 key = data & 0xf;
380
b4b8345b5366 ps3 fix
e065701@localhost.localdomain
parents: 352
diff changeset
19 value += key * PRIME[n++ & 7];
352
3f5289873643 add global_alloc.h
admin@mb22-no-macbook-2.local
parents: 210
diff changeset
20 data >>= 4;
167
c8b868871dce DrawSpan で使う Tile の Hash の扱いは class TileHash を生成する事に。
gongo@localhost.localdomain
parents:
diff changeset
21 }
c8b868871dce DrawSpan で使う Tile の Hash の扱いは class TileHash を生成する事に。
gongo@localhost.localdomain
parents:
diff changeset
22
c8b868871dce DrawSpan で使う Tile の Hash の扱いは class TileHash を生成する事に。
gongo@localhost.localdomain
parents:
diff changeset
23 return value % hashSize;
c8b868871dce DrawSpan で使う Tile の Hash の扱いは class TileHash を生成する事に。
gongo@localhost.localdomain
parents:
diff changeset
24 }
c8b868871dce DrawSpan で使う Tile の Hash の扱いは class TileHash を生成する事に。
gongo@localhost.localdomain
parents:
diff changeset
25
c8b868871dce DrawSpan で使う Tile の Hash の扱いは class TileHash を生成する事に。
gongo@localhost.localdomain
parents:
diff changeset
26 TileHash::TileHash(void)
c8b868871dce DrawSpan で使う Tile の Hash の扱いは class TileHash を生成する事に。
gongo@localhost.localdomain
parents:
diff changeset
27 {
352
3f5289873643 add global_alloc.h
admin@mb22-no-macbook-2.local
parents: 210
diff changeset
28 //hashSize = 263;
3f5289873643 add global_alloc.h
admin@mb22-no-macbook-2.local
parents: 210
diff changeset
29 //tableSize = sizeof(TilePtr)*hashSize;
167
c8b868871dce DrawSpan で使う Tile の Hash の扱いは class TileHash を生成する事に。
gongo@localhost.localdomain
parents:
diff changeset
30
c8b868871dce DrawSpan で使う Tile の Hash の扱いは class TileHash を生成する事に。
gongo@localhost.localdomain
parents:
diff changeset
31 table = (TilePtr*)malloc(tableSize);
c8b868871dce DrawSpan で使う Tile の Hash の扱いは class TileHash を生成する事に。
gongo@localhost.localdomain
parents:
diff changeset
32 clear();
c8b868871dce DrawSpan で使う Tile の Hash の扱いは class TileHash を生成する事に。
gongo@localhost.localdomain
parents:
diff changeset
33 }
c8b868871dce DrawSpan で使う Tile の Hash の扱いは class TileHash を生成する事に。
gongo@localhost.localdomain
parents:
diff changeset
34
c8b868871dce DrawSpan で使う Tile の Hash の扱いは class TileHash を生成する事に。
gongo@localhost.localdomain
parents:
diff changeset
35 int
380
b4b8345b5366 ps3 fix
e065701@localhost.localdomain
parents: 352
diff changeset
36 TileHash::put(memaddr key, TilePtr data)
167
c8b868871dce DrawSpan で使う Tile の Hash の扱いは class TileHash を生成する事に。
gongo@localhost.localdomain
parents:
diff changeset
37 {
380
b4b8345b5366 ps3 fix
e065701@localhost.localdomain
parents: 352
diff changeset
38 int hashval = hash(key);
167
c8b868871dce DrawSpan で使う Tile の Hash の扱いは class TileHash を生成する事に。
gongo@localhost.localdomain
parents:
diff changeset
39
c8b868871dce DrawSpan で使う Tile の Hash の扱いは class TileHash を生成する事に。
gongo@localhost.localdomain
parents:
diff changeset
40 for (int i = 0; i < hashSize/2; i++) {
352
3f5289873643 add global_alloc.h
admin@mb22-no-macbook-2.local
parents: 210
diff changeset
41 int index = (hashval + i*i)%hashSize;
167
c8b868871dce DrawSpan で使う Tile の Hash の扱いは class TileHash を生成する事に。
gongo@localhost.localdomain
parents:
diff changeset
42
352
3f5289873643 add global_alloc.h
admin@mb22-no-macbook-2.local
parents: 210
diff changeset
43 if (table[index] == 0) { // 空の table に入れる
3f5289873643 add global_alloc.h
admin@mb22-no-macbook-2.local
parents: 210
diff changeset
44 table[index] = data;
3f5289873643 add global_alloc.h
admin@mb22-no-macbook-2.local
parents: 210
diff changeset
45 return index;
3f5289873643 add global_alloc.h
admin@mb22-no-macbook-2.local
parents: 210
diff changeset
46 }
167
c8b868871dce DrawSpan で使う Tile の Hash の扱いは class TileHash を生成する事に。
gongo@localhost.localdomain
parents:
diff changeset
47 }
c8b868871dce DrawSpan で使う Tile の Hash の扱いは class TileHash を生成する事に。
gongo@localhost.localdomain
parents:
diff changeset
48
c8b868871dce DrawSpan で使う Tile の Hash の扱いは class TileHash を生成する事に。
gongo@localhost.localdomain
parents:
diff changeset
49 return -1;
c8b868871dce DrawSpan で使う Tile の Hash の扱いは class TileHash を生成する事に。
gongo@localhost.localdomain
parents:
diff changeset
50 }
c8b868871dce DrawSpan で使う Tile の Hash の扱いは class TileHash を生成する事に。
gongo@localhost.localdomain
parents:
diff changeset
51
c8b868871dce DrawSpan で使う Tile の Hash の扱いは class TileHash を生成する事に。
gongo@localhost.localdomain
parents:
diff changeset
52 TilePtr
380
b4b8345b5366 ps3 fix
e065701@localhost.localdomain
parents: 352
diff changeset
53 TileHash::get(memaddr key)
167
c8b868871dce DrawSpan で使う Tile の Hash の扱いは class TileHash を生成する事に。
gongo@localhost.localdomain
parents:
diff changeset
54 {
380
b4b8345b5366 ps3 fix
e065701@localhost.localdomain
parents: 352
diff changeset
55 int hashval = hash(key);
167
c8b868871dce DrawSpan で使う Tile の Hash の扱いは class TileHash を生成する事に。
gongo@localhost.localdomain
parents:
diff changeset
56
c8b868871dce DrawSpan で使う Tile の Hash の扱いは class TileHash を生成する事に。
gongo@localhost.localdomain
parents:
diff changeset
57 for (int i = 0; i < hashSize/2; i++) {
352
3f5289873643 add global_alloc.h
admin@mb22-no-macbook-2.local
parents: 210
diff changeset
58 int index = (hashval + i*i)%hashSize;
3f5289873643 add global_alloc.h
admin@mb22-no-macbook-2.local
parents: 210
diff changeset
59
3f5289873643 add global_alloc.h
admin@mb22-no-macbook-2.local
parents: 210
diff changeset
60 if (table[index] != NULL &&
380
b4b8345b5366 ps3 fix
e065701@localhost.localdomain
parents: 352
diff changeset
61 table[index]->address == key) {
352
3f5289873643 add global_alloc.h
admin@mb22-no-macbook-2.local
parents: 210
diff changeset
62 return table[index];
3f5289873643 add global_alloc.h
admin@mb22-no-macbook-2.local
parents: 210
diff changeset
63 }
167
c8b868871dce DrawSpan で使う Tile の Hash の扱いは class TileHash を生成する事に。
gongo@localhost.localdomain
parents:
diff changeset
64 }
c8b868871dce DrawSpan で使う Tile の Hash の扱いは class TileHash を生成する事に。
gongo@localhost.localdomain
parents:
diff changeset
65
c8b868871dce DrawSpan で使う Tile の Hash の扱いは class TileHash を生成する事に。
gongo@localhost.localdomain
parents:
diff changeset
66 return NULL;
c8b868871dce DrawSpan で使う Tile の Hash の扱いは class TileHash を生成する事に。
gongo@localhost.localdomain
parents:
diff changeset
67 }
c8b868871dce DrawSpan で使う Tile の Hash の扱いは class TileHash を生成する事に。
gongo@localhost.localdomain
parents:
diff changeset
68
c8b868871dce DrawSpan で使う Tile の Hash の扱いは class TileHash を生成する事に。
gongo@localhost.localdomain
parents:
diff changeset
69 void
380
b4b8345b5366 ps3 fix
e065701@localhost.localdomain
parents: 352
diff changeset
70 TileHash::remove(memaddr key)
173
56be4a6e5513 add scale
gongo@localhost.localdomain
parents: 167
diff changeset
71 {
380
b4b8345b5366 ps3 fix
e065701@localhost.localdomain
parents: 352
diff changeset
72 int hashval = hash(key);
173
56be4a6e5513 add scale
gongo@localhost.localdomain
parents: 167
diff changeset
73
56be4a6e5513 add scale
gongo@localhost.localdomain
parents: 167
diff changeset
74 for (int i = 0; i < hashSize/2; i++) {
352
3f5289873643 add global_alloc.h
admin@mb22-no-macbook-2.local
parents: 210
diff changeset
75 int index = (hashval + i*i)%hashSize;
3f5289873643 add global_alloc.h
admin@mb22-no-macbook-2.local
parents: 210
diff changeset
76
3f5289873643 add global_alloc.h
admin@mb22-no-macbook-2.local
parents: 210
diff changeset
77 if (table[index] != NULL &&
380
b4b8345b5366 ps3 fix
e065701@localhost.localdomain
parents: 352
diff changeset
78 table[index]->address == key) {
352
3f5289873643 add global_alloc.h
admin@mb22-no-macbook-2.local
parents: 210
diff changeset
79 table[index] = NULL;
3f5289873643 add global_alloc.h
admin@mb22-no-macbook-2.local
parents: 210
diff changeset
80 }
173
56be4a6e5513 add scale
gongo@localhost.localdomain
parents: 167
diff changeset
81 }
56be4a6e5513 add scale
gongo@localhost.localdomain
parents: 167
diff changeset
82 }
56be4a6e5513 add scale
gongo@localhost.localdomain
parents: 167
diff changeset
83
56be4a6e5513 add scale
gongo@localhost.localdomain
parents: 167
diff changeset
84 void
167
c8b868871dce DrawSpan で使う Tile の Hash の扱いは class TileHash を生成する事に。
gongo@localhost.localdomain
parents:
diff changeset
85 TileHash::clear(void)
c8b868871dce DrawSpan で使う Tile の Hash の扱いは class TileHash を生成する事に。
gongo@localhost.localdomain
parents:
diff changeset
86 {
c8b868871dce DrawSpan で使う Tile の Hash の扱いは class TileHash を生成する事に。
gongo@localhost.localdomain
parents:
diff changeset
87 bzero(table, tableSize);
c8b868871dce DrawSpan で使う Tile の Hash の扱いは class TileHash を生成する事に。
gongo@localhost.localdomain
parents:
diff changeset
88 }