-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdictionary.h
99 lines (85 loc) · 3.11 KB
/
dictionary.h
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
//
// Created by alexi on 11/11/2020.
//
#ifndef AVLTREE_DICTIONARY_H
#define AVLTREE_DICTIONARY_H
#include <vector>
#include <utility>
using std::pair;
using std::vector;
/**
* Dictionary defines a templated pure-virtual interface for a dictionary.
* K is the key type, V the value type
*/
template <typename K, typename V>
class Dictionary {
public:
virtual ~Dictionary() {}
/**
* Returns the size of the dictionary.
* @return The number of key-value pairs in the data structure.
*/
virtual int getSize() = 0;
/**
* Returns true if the dictionary is empty.
* @return true if there are no elements in the dictionary.
*/
virtual bool isEmpty() = 0;
/**
* Inserts the key-value pair into the dictionary
* @param key The key for the new mapping.
* @param value The value to associate with that key.
* @throws runtime_error If they key already exists.
*/
virtual void insert(K key, V value) = 0;
/**
* Finds the element indexed by the given key and updates its value to the
* provided value parameter.
* @param key The key of the mapping to update.
* @param value The new value to associate with that key.
* @throws runtime_error if the key is not found in the dictionary.
*/
virtual void update(K key, V value) = 0;
/**
* Returns the value associated with the given key
* @param key The key of the mapping to find.
* @return The value associated with that key.
* @throws runtime_error If the key is not found in the dictionary.
*/
virtual V get(K key) = 0;
/**
* Determines if a given key exists in a mapping in this dictionary.
* @param key The key to look for.
* @return true if item in the dictionary has this key.
*/
virtual bool contains(K key) = 0;
/**
* Deletes the element with given key from the dictionary.
* @param key The key to remove.
* @throws runtime_error If they key was not already in this dictionary.
*/
virtual void remove(K key) = 0;
/**
* Obtains a vector containing all keys in this dictionary.
* @return An STL vector object containing the keys in this
* dictionary (in no particular order).
*/
virtual vector<K> getKeys() = 0;
/**
* Obtains a vector containing all key-value pairs in this dictionary.
* @return An STL vector object containing the key-value pairs
* in the dictionary (in no particular order).
*/
virtual vector<pair<K,V>> getItems() = 0;
// You can safely ignore the following code. This eliminates some default
// class routines, preventing you from using them accidentally.
// Specifically, we are disabling the use of the copy constructor and the
// copy assignment operator. You can read more here:
// http://www.cplusplus.com/articles/y8hv0pDG/
public:
Dictionary() { }
private:
Dictionary(const Dictionary& other) = delete;
Dictionary& operator=(const Dictionary& other) = delete;
};
#endif //AVLTREE_DICTIONARY_H