Subversion Repositories gelsvn

Rev

Rev 601 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 601 Rev 630
1
/* ----------------------------------------------------------------------- *
1
/* ----------------------------------------------------------------------- *
2
 * This file is part of GEL, http://www.imm.dtu.dk/GEL
2
 * This file is part of GEL, http://www.imm.dtu.dk/GEL
3
 * Copyright (C) the authors and DTU Informatics
3
 * Copyright (C) the authors and DTU Informatics
4
 * For license and list of authors, see ../../doc/intro.pdf
4
 * For license and list of authors, see ../../doc/intro.pdf
5
 * ----------------------------------------------------------------------- */
5
 * ----------------------------------------------------------------------- */
6
 
6
 
7
/**
7
/**
8
 * @file HashKey.h
8
 * @file HashKey.h
9
 * @brief Kehy class for hash tables.
9
 * @brief Kehy class for hash tables.
10
 */
10
 */
11
#ifndef __UTIL_HASHKEY_H
11
#ifndef __UTIL_HASHKEY_H
12
#define __UTIL_HASHKEY_H
12
#define __UTIL_HASHKEY_H
13
 
13
 
14
#include <stdlib.h>
14
#include <stdlib.h>
15
#include <limits.h>
15
#include <limits.h>
16
#include "../CGLA/Vec3uc.h"
16
#include "../CGLA/Vec3uc.h"
17
#include "../CGLA/Vec3usi.h"
17
#include "../CGLA/Vec3usi.h"
18
 
18
 
19
namespace Util
19
namespace Util
20
{
20
{
21
 
21
 
22
	
22
	
23
	extern int randoms1[UCHAR_MAX];
23
	extern int randoms1[UCHAR_MAX];
24
	extern int randoms2[UCHAR_MAX];
24
	extern int randoms2[UCHAR_MAX];
25
	extern int randoms3[UCHAR_MAX];
25
	extern int randoms3[UCHAR_MAX];
26
 
26
 
27
	bool init_randoms();
27
	bool init_randoms();
28
	void do_init_randoms();
28
	void do_init_randoms();
29
	
29
	
30
	struct HashKey3uc
30
	struct HashKey3uc
31
	{
31
	{
32
		CGLA::Vec3uc key;
32
		CGLA::Vec3uc key;
33
 
33
 
34
		HashKey3uc() {do_init_randoms();}
34
		HashKey3uc() {do_init_randoms();}
35
		HashKey3uc(CGLA::Vec3uc _key): key(_key) {do_init_randoms();}
35
		HashKey3uc(CGLA::Vec3uc _key): key(_key) {do_init_randoms();}
36
		HashKey3uc(CGLA::Vec3i _key): key(_key) {do_init_randoms();}
36
		HashKey3uc(CGLA::Vec3i _key): key(_key) {do_init_randoms();}
37
		
37
		
38
		int hash(int use_size) const
38
		int hash(int use_size) const
39
		{
39
		{
40
			return int((randoms1[key[0]] >> (key[1]&0x0f)) +
40
			return int((randoms1[key[0]] >> (key[1]&0x0f)) +
41
								 (randoms2[key[1]] >> (key[2]&0x0f)) +
41
								 (randoms2[key[1]] >> (key[2]&0x0f)) +
42
								 (randoms3[key[2]] >> (key[0]&0x0f))) & (use_size-1);
42
								 (randoms3[key[2]] >> (key[0]&0x0f))) & (use_size-1);
43
		}
43
		}
44
		
44
		
45
		bool operator==(const HashKey3uc& k2) const {return key==k2.key;}
45
		bool operator==(const HashKey3uc& k2) const {return key==k2.key;}
46
		bool operator!=(const HashKey3uc& k2) const {return !(key==k2.key);}
46
		bool operator!=(const HashKey3uc& k2) const {return !(key==k2.key);}
47
	};
47
	};
48
 
48
 
49
	struct HashKey3usi
49
	struct HashKey3usi
50
	{
50
	{
51
		CGLA::Vec3usi key;
51
		CGLA::Vec3usi key;
52
 
52
 
53
		HashKey3usi() {do_init_randoms();}
53
		HashKey3usi() {do_init_randoms();}
54
		HashKey3usi(CGLA::Vec3usi _key): key(_key) {do_init_randoms();}
54
		HashKey3usi(CGLA::Vec3usi _key): key(_key) {do_init_randoms();}
55
		HashKey3usi(CGLA::Vec3i _key): key(_key) {do_init_randoms();}
55
		HashKey3usi(CGLA::Vec3i _key): key(_key) {do_init_randoms();}
56
 
56
 
57
		int hash(int use_size) const
57
		int hash(int use_size) const
58
		{
58
		{
59
			return int(
59
			return int(
60
								 ((randoms1[key[0]&0xff00>>8] * randoms2[key[1]&0xff] >> (key[2]&0x0f))
60
								 ((randoms1[key[0]&0xff00>>8] * randoms2[key[1]&0xff] >> (key[2]&0x0f))
61
									+ (randoms2[key[1]&0xff00>>8] * randoms1[key[2]&0xff] >> (key[0]&0x0f))
61
									+ (randoms2[key[1]&0xff00>>8] * randoms1[key[2]&0xff] >> (key[0]&0x0f))
62
									+ (randoms3[key[2]&0xff00>>8] * randoms3[key[0]&0xff] >> (key[1]&0x0f)))
62
									+ (randoms3[key[2]&0xff00>>8] * randoms3[key[0]&0xff] >> (key[1]&0x0f)))
63
								 & (use_size-1));
63
								 & (use_size-1));
64
		}
64
		}
65
	
65
	
66
		bool operator==(const HashKey3usi& k2) const {return key==k2.key;}
66
		bool operator==(const HashKey3usi& k2) const {return key==k2.key;}
67
		bool operator!=(const HashKey3usi& k2) const {return !(key==k2.key);}
67
		bool operator!=(const HashKey3usi& k2) const {return !(key==k2.key);}
68
	};
68
	};
69
 
69
 
70
	struct HashKey1c
70
	struct HashKey1c
71
	{
71
	{
72
		unsigned char key;
72
		unsigned char key;
73
 
73
 
74
		HashKey1c() {do_init_randoms();}
74
		HashKey1c() {do_init_randoms();}
75
		HashKey1c(unsigned char _key): key(_key) {do_init_randoms();}
75
		HashKey1c(unsigned char _key): key(_key) {do_init_randoms();}
76
 
76
 
77
		int hash(int use_size) const
77
		int hash(int use_size) const
78
		{
78
		{
79
			return int(randoms1[key] & (use_size-1));
79
			return int(randoms1[key] & (use_size-1));
80
		}
80
		}
81
	
81
	
82
		bool operator==(const HashKey1c& k2) const {return key==k2.key;}
82
		bool operator==(const HashKey1c& k2) const {return key==k2.key;}
83
		bool operator!=(const HashKey1c& k2) const {return !(key==k2.key);}
83
		bool operator!=(const HashKey1c& k2) const {return !(key==k2.key);}
84
	};
84
	};
85
}
85
}
86
 
86
 
87
 
87
 
88
#endif
88
#endif
89
 
89