-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStateTable.java
More file actions
63 lines (55 loc) · 1.59 KB
/
StateTable.java
File metadata and controls
63 lines (55 loc) · 1.59 KB
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
58
59
60
61
62
63
/**
* This class implements the stateTable map BackEnd and provides the necessary functionality
* for FrontEnd
* @author Zach Austin
*
*/
public class StateTable extends HashTableMap {
public int capacity;
public HashTableMap stateTable = new HashTableMap(10);
public StateTable(int capacity) {
this.capacity = capacity;
this.stateTable = new HashTableMap(capacity);
}
public StateTable() {
this.capacity = 10;
this.stateTable = new HashTableMap();
}
/*
* keyToIndex takes a key as an argument and returns the corresponding index
* for that key in the Hash Table
* @param key - key to find index for
* @return - int of corresponding index
* */
public int keyToIndex(String key) {
return Math.abs(key.hashCode() % capacity);
}
/*
* insertInfo allows the functionality of adding info
* to a state in the Hash Table
* @param key - key of state being added to
* @param info - calue of information being added to state
* @return - true if added successfully
*/
public boolean insertInfo(String key, String info) {
return stateTable.put(key, info);
}
/*
* remove allows the functionality of removing value info
* from a state in the Hash Table
* @param key - key of info being removed
* @return - String of value info removed
* */
public String remove(String key) {
return stateTable.remove(key).toString();
}
/*
* clears allows the functionality of clearing the stateTable to start with a new,
* empty stateTable
*
* */
public void clear() {
stateTable.clear();
return;
}
}