Mercurial > hg > Members > kono > Cerium
annotate TaskManager/kernel/memory/MemHash.cc @ 388:82cb9368e3ff
MemHash (OS X version)
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Thu, 06 Aug 2009 23:30:26 +0900 (2009-08-06) |
parents | 5e2d30bfbf23 |
children | 60aa3f241b10 |
rev | line source |
---|---|
184 | 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> |
383
25c820b6060e
fix header, MemHash in kernel
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
380
diff
changeset
|
4 #include "MemHash.h" |
167
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 |
383
25c820b6060e
fix header, MemHash in kernel
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
380
diff
changeset
|
11 MemHash::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 | 17 for (uint32 i = 0; i < sizeof(memaddr) * 2; i ++) { |
352 | 18 key = data & 0xf; |
380 | 19 value += key * PRIME[n++ & 7]; |
352 | 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 |
388
82cb9368e3ff
MemHash (OS X version)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
387
diff
changeset
|
26 MemHash::MemHash() |
167
c8b868871dce
DrawSpan で使う Tile の Hash の扱いは class TileHash を生成する事に。
gongo@localhost.localdomain
parents:
diff
changeset
|
27 { |
352 | 28 //hashSize = 263; |
383
25c820b6060e
fix header, MemHash in kernel
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
380
diff
changeset
|
29 //tableSize = sizeof(MemorySegmentPtr)*hashSize; |
167
c8b868871dce
DrawSpan で使う Tile の Hash の扱いは class TileHash を生成する事に。
gongo@localhost.localdomain
parents:
diff
changeset
|
30 |
383
25c820b6060e
fix header, MemHash in kernel
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
380
diff
changeset
|
31 table = (MemorySegmentPtr*)malloc(tableSize); |
167
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 |
383
25c820b6060e
fix header, MemHash in kernel
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
380
diff
changeset
|
36 MemHash::put(memaddr key, MemorySegmentPtr data) |
167
c8b868871dce
DrawSpan で使う Tile の Hash の扱いは class TileHash を生成する事に。
gongo@localhost.localdomain
parents:
diff
changeset
|
37 { |
380 | 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 | 41 int index = (hashval + i*i)%hashSize; |
167
c8b868871dce
DrawSpan で使う Tile の Hash の扱いは class TileHash を生成する事に。
gongo@localhost.localdomain
parents:
diff
changeset
|
42 |
352 | 43 if (table[index] == 0) { // 空の table に入れる |
44 table[index] = data; | |
45 return index; | |
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 |
383
25c820b6060e
fix header, MemHash in kernel
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
380
diff
changeset
|
52 MemorySegmentPtr |
25c820b6060e
fix header, MemHash in kernel
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
380
diff
changeset
|
53 MemHash::get(memaddr key) |
167
c8b868871dce
DrawSpan で使う Tile の Hash の扱いは class TileHash を生成する事に。
gongo@localhost.localdomain
parents:
diff
changeset
|
54 { |
380 | 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 | 58 int index = (hashval + i*i)%hashSize; |
59 | |
60 if (table[index] != NULL && | |
380 | 61 table[index]->address == key) { |
352 | 62 return table[index]; |
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 |
383
25c820b6060e
fix header, MemHash in kernel
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
380
diff
changeset
|
70 MemHash::remove(memaddr key) |
173 | 71 { |
380 | 72 int hashval = hash(key); |
173 | 73 |
74 for (int i = 0; i < hashSize/2; i++) { | |
352 | 75 int index = (hashval + i*i)%hashSize; |
76 | |
77 if (table[index] != NULL && | |
380 | 78 table[index]->address == key) { |
352 | 79 table[index] = NULL; |
80 } | |
173 | 81 } |
82 } | |
83 | |
84 void | |
383
25c820b6060e
fix header, MemHash in kernel
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
380
diff
changeset
|
85 MemHash::clear(void) |
167
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 } |
383
25c820b6060e
fix header, MemHash in kernel
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
380
diff
changeset
|
89 |
25c820b6060e
fix header, MemHash in kernel
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
380
diff
changeset
|
90 /* end */ |