-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgramState.cpp
More file actions
40 lines (38 loc) · 968 Bytes
/
ProgramState.cpp
File metadata and controls
40 lines (38 loc) · 968 Bytes
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
#include "ProgramState.h"
ProgramState::ProgramState()
{
SizeHash = 41;
HashTableCommand.resize(41);
}
int ProgramState::HashFunction(int numberOfCommand)
{
return numberOfCommand% SizeHash;
}
void ProgramState::insert(Command* com)
{
int index = HashFunction(com->getNumberOfCommand());
HashTableCommand[index].push_back(com);
}
Command* ProgramState::search(int numberOfCommand)
{
if (!HashTableCommand.empty()) {
int index = HashFunction(numberOfCommand);
if (index < HashTableCommand.size()) {
for (auto x : HashTableCommand[index]) {
if (x->getNumberOfCommand() == numberOfCommand) {
return x;
}
}
}
}
return NULL;
}
void ProgramState::Deleted(Command com) {
int index = HashFunction(com.getNumberOfCommand());
for (auto it = HashTableCommand[index].begin(); it != HashTableCommand[index].end(); ++it) {
if ((*it)->getNumberOfCommand() == com.getNumberOfCommand()) {
HashTableCommand[index].erase(it);
break;
}
}
}