-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInefficientMap.h
More file actions
88 lines (63 loc) · 2.06 KB
/
InefficientMap.h
File metadata and controls
88 lines (63 loc) · 2.06 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
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
#ifndef _INEFFICIENT_MAP_H
#define _INEFFICIENT_MAP_H
#include "Swap.h"
#include "TwoWayList.h"
using namespace std;
template <class Key, class Data>
class InefficientMap {
public:
typedef Key keyType;
typedef Data dataType;
// constructor & destructor
InefficientMap() {}
virtual ~InefficientMap() {}
// remove all the content
void Clear(void);
// the length of the map
int Length();
// inserts the key/data pair into the structure
void Insert (Key &key, Data &data);
// this takes the contents of suckMeUp and adds them, all at once,
// to *this; no checks of any kind are done to remove duplicates, etc.
void SuckUp (InefficientMap &suckMeUp);
// removes one (any) instance of the given key from the map...
// returns a 1 on success and a zero if the given key was not found
int Remove (Key &findMe, Key &putKeyHere, Data &putDataHere);
// attempts to locate the given key
// returns 1 if it is, 0 otherwise
int IsThere (Key &findMe);
// returns a reference to the data associated with the given search key
// if the key is not there, then a garbage (newly initialized) Data item is
// returned. "Plays nicely" with IsThere in the sense that if IsThere found
// an item, Find will immediately return that item w/o having to locate it
Data &Find (Key &findMe);
// swap two of the maps
void Swap (InefficientMap &withMe);
// get the content from another map (without destroying it)
void CopyFrom(InefficientMap& other);
///////////// ITERATOR INTERFAACE //////////////
// look at the current item
Key& CurrentKey ();
Data& CurrentData ();
// move the current pointer position backward through the list
void Retreat ();
// move the current pointer position forward through the list
void Advance ();
// operations to consult state
bool AtStart ();
bool AtEnd ();
// operations to move the the start of end of a list
void MoveToStart ();
void MoveToFinish ();
private:
struct Node {
Key key;
Data data;
void Swap (Node &swapMe) {
key.Swap (swapMe.key);
data.Swap (swapMe.data);
}
};
TwoWayList <Node> container;
};
#endif