-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHashTable.cpp
57 lines (48 loc) · 1.41 KB
/
HashTable.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include "HashTable.h"
#include <sstream>
//-----------------------------------------------------------------------------
HashTable::HashTable(
GLData *i_glData
):
m_glData(i_glData),
m_currentIndex(0)
{
}
HashTable::HashTable():m_currentIndex(0)
{}
//-----------------------------------------------------------------------------
std::string HashTable::convert (float number){
std::stringstream buff;
buff.precision(6);
buff<<number;
return buff.str();
}
//-----------------------------------------------------------------------------
void HashTable::setGLData(GLData *i_glData)
{
m_glData = i_glData;
}
//-----------------------------------------------------------------------------
unsigned int HashTable::getIndex(const gmtl::Vec3f &i_vertex
)
{
std::string input = convert(i_vertex[0]) + " " + convert(i_vertex[1])
+ " " + convert(i_vertex[2]);
std::unordered_map<std::string,unsigned int>::const_iterator got =
mymap.find(input);
if(got == mymap.end())
{
std::pair<std::string, unsigned int> pair(input,m_currentIndex);
m_currentIndex++;
mymap.insert(pair);
m_glData->addVertex(gmtl::Vec3f(i_vertex[0],i_vertex[1],i_vertex[2]));
return m_currentIndex-1;
}
else
{
return got->second;
}
}
//-----------------------------------------------------------------------------
HashTable::~HashTable()
{}