This file is indexed.

/usr/include/ucommon/mapref.h is in libucommon-dev 7.0.0-9.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
// Copyright (C) 2015 Cherokees of Idaho.
//
// This file is part of GNU uCommon C++.
//
// GNU uCommon C++ is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// GNU uCommon C++ is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with GNU uCommon C++.  If not, see <http://www.gnu.org/licenses/>.

/**
 * Maps of thread-safe strongly typed heap objects.  This is used for
 * maps of smart pointers to immutable heap instances of object types.
 * Shared and exclusive locking is used based on lookup or modify operations. 
 * @file ucommon/mapref.h
 */

#ifndef _UCOMMON_MAPREF_H_
#define _UCOMMON_MAPREF_H_

#ifndef _UCOMMON_CPR_H_
#include <ucommon/cpr.h>
#endif

#ifndef _UCOMMON_ATOMIC_H_
#include <ucommon/atomic.h>
#endif

#ifndef _UCOMMON_PROTOCOLS_H_
#include <ucommon/protocols.h>
#endif

#ifndef _UCOMMON_OBJECT_H_
#include <ucommon/object.h>
#endif

#ifndef	_UCOMMON_TYPEREF_H_
#include <ucommon/typeref.h>
#endif

#ifndef _UCOMMON_LINKED_H_
#include <ucommon/linked.h>
#endif

#ifndef _UCOMMON_THREAD_H_
#include <ucommon/thread.h>
#endif

namespace ucommon {

class __EXPORT MapRef : public TypeRef
{
protected:
	class Map;
    class Instance;

	class __EXPORT Index : public LinkedObject
	{
    private:
        __DELETE_COPY(Index);

	public:
		friend class Map;

		explicit Index(LinkedObject **origin);

		Index();

		Counted *key, *value;
	};

	class __EXPORT Map : public Counted
	{
    private:
        __DELETE_COPY(Map);

	protected:
        friend class Instance;

		virtual void dealloc() __OVERRIDE;

	public:
		friend class MapRef;

		memalloc pool;
		condlock_t lock;
		LinkedObject *free, *last;
		size_t count, alloc;

		explicit Map(void *addr, size_t indexes, size_t paging = 0);
	
		inline LinkedObject **get(void) {
			return reinterpret_cast<LinkedObject **>(((caddr_t)(this)) + sizeof(Map));
		}

		Index *create(size_t path);

		Index *append();

		void remove(Index *index, size_t path);

		LinkedObject *modify(size_t key = 0);

		LinkedObject *access(size_t key = 0);
	};

	class __EXPORT Instance
	{
	protected:
		Map *map;
		LinkedObject *index;
		size_t path;

		Instance();

		Instance(MapRef& from);

		explicit Instance(Map *map);

		Instance(const Instance& copy);

		void assign(const Instance& copy);

		void assign(MapRef& from);

		void drop(void);

		Counted *key();

		Counted *value();

	public:
		~Instance();

		void rewind();

		bool next();

		bool eol();

		bool top();

		inline operator bool() {
			return index != NULL;
		}

		inline bool operator!() {
			return index == NULL;
		}
	};

	MapRef(size_t paths, size_t paging = 0);
	MapRef(const MapRef& copy);
	MapRef();

	void assign(TypeRef& key, TypeRef& value);

	static Map *create(size_t paths, size_t paging = 0);

	linked_pointer<Index> access(size_t keyvalue = 0);

	linked_pointer<Index> modify(size_t keyvalue = 0);

	void append(TypeRef& value);

	void add(size_t path, TypeRef& key, TypeRef& value);

	void update(Index *ind, TypeRef& value);

	void remove(Index *ind, size_t path = 0);

	void release();

	void commit();

public:
	size_t count(void);

	size_t used(void);

	void purge(void);

	static size_t index(size_t& key, const uint8_t *addr, size_t len);
};

template<typename T>
inline size_t mapkeypath(typeref<T>& object)
{
	size_t path = sizeof(T);
	return MapRef::index(path, (const uint8_t *)(object()), sizeof(T));
}

template<>
inline size_t mapkeypath<const char *>(typeref<const char *>& object)
{
	size_t path = 1;
	return MapRef::index(path, (const uint8_t *)(*object), object.len());
}

template<>
inline size_t mapkeypath<const uint8_t *>(typeref<const uint8_t *>& object)
{
	size_t path = object.size();
	return MapRef::index(path, *object, object.size());
}

template<typename K, typename V>
class mapref : public MapRef
{
protected:
	bool erase(typeref<K>& key) {
		size_t path = mapkeypath<K>(key);
		linked_pointer<Index> ip = modify(path);
		while(is(ip)) {
			typeref<K> kv(ip->key);
			if(is(kv) && kv == key) {
				MapRef::remove(*ip, path);
				MapRef::commit();
				return true;
			}
			ip.next();
		}
		MapRef::commit();
		return false;
	}	

public:
	class instance : public MapRef::Instance
	{
	public:
		inline instance(const instance& copy) : Instance(static_cast<const Instance&>(copy)) {};

		inline instance(mapref& from) : Instance(static_cast<MapRef&>(from)) {};

		inline instance() : Instance() {};

		inline typeref<K> key() {
			return typeref<K>(Instance::key());
		}

		inline typeref<V> value() {
			return typeref<V>(Instance::value());
		}

		inline instance& operator++() {
			next();
			return *this;
		}

		inline instance& operator=(const instance& copy) {
			assign(static_cast<const Instance&>(copy));
			return *this;
		}

		inline instance& operator=(mapref& from) {
			assign(static_cast<MapRef&>(from));
			return *this;
		}
	};

	inline mapref(const mapref& copy) : MapRef(copy) {};

	inline mapref(size_t paths = 37, size_t paging = 0) : MapRef(paths, paging) {};

	inline mapref& operator=(const mapref& copy) {
		TypeRef::set(copy);
		return *this;
	}

	inline instance operator*() {
		return instance(this);
	}

	void value(typeref<K>& key, typeref<V>& val) {
		size_t path = mapkeypath<K>(key);
		linked_pointer<Index> ip = modify(path);
		while(is(ip)) {
			typeref<K> kv(ip->key);
			if(is(kv) && kv == key) {
				update(*ip, val);
				commit();
				return;
			}
			ip.next();
		}
		add(path, key, val);
		commit();
	}

	typeref<V> at(typeref<K>& key) {
		linked_pointer<Index> ip = access(mapkeypath<K>(key));
		while(is(ip)) {
			typeref<K> kv(ip->key);
			if(is(kv) && kv == key) {
				typeref<V> result(ip->value);
				release();
				return result;
			}
			ip.next();
		}
		release();
		return typeref<V>();
	}	

	typeref<V> take(typeref<K>& key) {
		size_t path = mapkeypath<K>(key);
		linked_pointer<Index> ip = modify(path);
		while(is(ip)) {
			typeref<K> kv(ip->key);
			if(is(kv) && kv == key) {
				typeref<V> result(ip->value);
				if(is(result.is))
					MapRef::remove(*ip, path);
				commit();
				return result;
			}
			ip.next();
		}
		commit();
		return typeref<V>();
	}	

	inline bool remove(typeref<K>& key) {
		return erase(key);
	}

	inline bool remove(K k) {
		typeref<K> key(k);
		return erase(key);
	}

	inline typeref<V> operator()(typeref<K>& key) {
		return at(key);
	}

	inline typeref<V> operator()(K k) {
		typeref<K> key(k);
		return at(key);
	}

	inline void operator()(typeref<K>& key, typeref<V>& val) {
		value(key, val);
	}	

	inline void operator()(K k, V v) {
		typeref<K> key(k);
		typeref<V> val(v);
		value(key, val);
	}
};

template<typename T>
class listref : public MapRef
{
protected:
	bool erase(typeref<T>& value) {
		linked_pointer<Index> ip = modify();
		while(ip) {
			typeref<T> kv(ip->value);
			if(is(kv) && kv == value) {
				MapRef::remove(*ip);
				MapRef::commit();
				return true;
			}
			ip.next();
		}
		MapRef::commit();
		return false;
	}
	
public:
	class instance : public MapRef::Instance
	{
	public:
		inline instance(const instance& copy) : Instance(static_cast<const Instance&>(copy)) {};

		inline instance(listref& from) : Instance(static_cast<MapRef&>(from)) {};

		inline instance() : Instance() {};

		inline const T& operator*() {
			return *(Instance::value());
		}

		inline const T* operator->() {
			return Instance::value();
		}

		inline instance& operator++() {
			next();
			return *this;
		}

		inline instance& operator=(const instance& copy) {
			assign(static_cast<const Instance&>(copy));
			return *this;
		}

		inline instance& operator=(listref& from) {
			assign(static_cast<MapRef&>(from));
			return *this;
		}
	};

	inline listref(const listref& copy) : MapRef(copy) {};

	inline listref(size_t paging = 0) : MapRef(1, paging) {};

	inline listref& operator=(const listref& copy) {
		TypeRef::set(copy);
		return *this;
	}

	inline instance operator*() {
		return instance(this);
	}

	inline listref& operator<<(typeref<T>& value) {
		append(value);
		return *this;
	}

	inline listref& operator<<(T t) {
		typeref<T> v(t);
		append(v);
		return *this;
	}

	inline bool remove(typeref<T>& key) {
		return erase(key);
	}

	inline bool remove(T t) {
		typeref<T> key(t);
		return erase(key);
	}

	inline typeref<T> take(size_t offset) {
		linked_pointer<Index> ip = modify();
		while(is(ip) && offset--) {
			ip.next();
		}
		typeref<T> v(ip->value);
		if(is(v))
			MapRef::remove(*ip);
		commit();
		return v;
	}

	inline typeref<T> at(size_t offset) {
		linked_pointer<Index> ip = access();
		while(ip && offset--) {
			ip.next();
		}
		typeref<T> v(ip->value);
		release();
		return v;
	}

	inline typeref<T> operator[](size_t offset) {
		return at(offset);
	}
};


} // namespace

#endif