Skip to content

Commit 6d44ee5

Browse files
jesse99brson
authored andcommitted
---
yaml --- r: 36749 b: refs/heads/try2 c: fc740a7 h: refs/heads/master i: 36747: b700e8b v: v3
1 parent 68bf47c commit 6d44ee5

File tree

4 files changed

+46
-17
lines changed

4 files changed

+46
-17
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: eb8fd119c65c67f3b1b8268cc7341c22d39b7b61
55
refs/heads/try: d324a424d8f84b1eb049b12cf34182bda91b0024
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: d4daa78aa374c3f129e2fbff3ad57484e9d4b8e1
8+
refs/heads/try2: fc740a729721d5063be367de99b5fcb62a99f2d7
99
refs/heads/incoming: d9317a174e434d4c99fc1a37fd7dc0d2f5328d37
1010
refs/heads/dist-snap: 22efa39382d41b084fde1719df7ae8ce5697d8c9
1111
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596

branches/try2/src/rt/util/array_list.h

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,32 @@
1616
#include <stddef.h>
1717

1818
/**
19-
* A simple, resizable array list.
19+
* A simple, resizable array list. Note that this only works with POD types
20+
* (because data is grown via realloc).
2021
*/
2122
template<typename T> class array_list {
2223
static const size_t INITIAL_CAPACITY = 8;
2324
size_t _size;
2425
T * _data;
2526
size_t _capacity;
27+
private:
28+
// private and left undefined to disable copying
29+
array_list(const array_list& rhs);
30+
array_list& operator=(const array_list& rhs);
2631
public:
2732
array_list();
2833
~array_list();
29-
size_t size();
34+
size_t size() const;
3035
int32_t append(T value);
3136
int32_t push(T value);
3237
bool pop(T *value);
3338
bool replace(T old_value, T new_value);
34-
int32_t index_of(T value);
35-
bool is_empty();
39+
int32_t index_of(T value) const;
40+
bool is_empty() const;
3641
T* data();
42+
const T* data() const;
3743
T & operator[](size_t index);
44+
const T & operator[](size_t index) const;
3845
};
3946

4047
template<typename T>
@@ -50,7 +57,7 @@ array_list<T>::~array_list() {
5057
}
5158

5259
template<typename T> size_t
53-
array_list<T>::size() {
60+
array_list<T>::size() const {
5461
return _size;
5562
}
5663

@@ -97,7 +104,7 @@ array_list<T>::replace(T old_value, T new_value) {
97104
}
98105

99106
template<typename T> int32_t
100-
array_list<T>::index_of(T value) {
107+
array_list<T>::index_of(T value) const {
101108
for (size_t i = 0; i < _size; i++) {
102109
if (_data[i] == value) {
103110
return i;
@@ -111,8 +118,13 @@ array_list<T>::operator[](size_t index) {
111118
return _data[index];
112119
}
113120

121+
template<typename T> const T &
122+
array_list<T>::operator[](size_t index) const {
123+
return _data[index];
124+
}
125+
114126
template<typename T> bool
115-
array_list<T>::is_empty() {
127+
array_list<T>::is_empty() const {
116128
return _size == 0;
117129
}
118130

@@ -121,4 +133,9 @@ array_list<T>::data() {
121133
return _data;
122134
}
123135

136+
template<typename T> const T*
137+
array_list<T>::data() const {
138+
return _data;
139+
}
140+
124141
#endif /* ARRAY_LIST_H */

branches/try2/src/rt/util/hash_map.h

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ template<typename K, typename V> class hash_map {
2626
UT_hash_handle hh;
2727
};
2828
map_entry * _head;
29+
private:
30+
// private and left undefined to disable copying
31+
hash_map(const hash_map& rhs);
32+
hash_map& operator=(const hash_map& rhs);
2933
public:
3034
hash_map();
3135
~hash_map();
@@ -54,7 +58,7 @@ template<typename K, typename V> class hash_map {
5458
* true if the value was found and updates the specified *value parameter
5559
* with the associated value, or false otherwise.
5660
*/
57-
bool get(K key, V *value);
61+
bool get(K key, V *value) const;
5862

5963
/**
6064
* Removes a key-value pair from this hash map.
@@ -71,7 +75,7 @@ template<typename K, typename V> class hash_map {
7175
* returns:
7276
* true if the specified key exists in this hash map, or false otherwise.
7377
*/
74-
bool contains(K key);
78+
bool contains(K key) const;
7579

7680
/**
7781
* Removes the value associated with the specified key from this hash map.
@@ -86,9 +90,9 @@ template<typename K, typename V> class hash_map {
8690
/**
8791
* Returns the number of key-value pairs in this hash map.
8892
*/
89-
size_t count();
93+
size_t count() const;
9094

91-
bool is_empty() {
95+
bool is_empty() const {
9296
return count() == 0;
9397
}
9498

@@ -124,7 +128,7 @@ hash_map<K,V>::put(K key, V value) {
124128
}
125129

126130
template<typename K, typename V> bool
127-
hash_map<K,V>::get(K key, V *value) {
131+
hash_map<K,V>::get(K key, V *value) const {
128132
map_entry *entry = NULL;
129133
HASH_FIND(hh, _head, &key, sizeof(K), entry);
130134
if (entry == NULL) {
@@ -146,7 +150,7 @@ hash_map<K,V>::set(K key, V value) {
146150
}
147151

148152
template<typename K, typename V> bool
149-
hash_map<K,V>::contains(K key) {
153+
hash_map<K,V>::contains(K key) const {
150154
V value;
151155
return get(key, &value);
152156
}
@@ -184,7 +188,7 @@ hash_map<K,V>::remove(K key) {
184188
}
185189

186190
template<typename K, typename V> size_t
187-
hash_map<K,V>::count() {
191+
hash_map<K,V>::count() const {
188192
return HASH_CNT(hh, _head);
189193
}
190194

branches/try2/src/rt/util/indexed_list.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,15 @@ template<typename T> class indexed_list {
4545
* Same as pop(), except that it returns NULL if the list is empty.
4646
*/
4747
virtual T* pop_value();
48-
virtual size_t length() {
48+
virtual size_t length() const {
4949
return list.size();
5050
}
51-
virtual bool is_empty() {
51+
virtual bool is_empty() const {
5252
return list.is_empty();
5353
}
5454
virtual int32_t remove(T* value);
5555
virtual T * operator[](int32_t index);
56+
virtual const T * operator[](int32_t index) const;
5657
virtual ~indexed_list() {}
5758
};
5859

@@ -104,4 +105,11 @@ indexed_list<T>::operator[](int32_t index) {
104105
return value;
105106
}
106107

108+
template <typename T> const T *
109+
indexed_list<T>::operator[](int32_t index) const {
110+
T *value = list[index];
111+
assert(value->list_index == index);
112+
return value;
113+
}
114+
107115
#endif /* INDEXED_LIST_H */

0 commit comments

Comments
 (0)