CBMC
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
sparse_vector.h
Go to the documentation of this file.
1/*******************************************************************\
2
3Module: Sparse Vectors
4
5Author: Romain Brenguier
6
7\*******************************************************************/
8
11
12#ifndef CPROVER_UTIL_SPARSE_VECTOR_H
13#define CPROVER_UTIL_SPARSE_VECTOR_H
14
15#include "invariant.h"
16
17#include <cstdint>
18#include <map>
19
20template<class T> class sparse_vectort
21{
22protected:
23 typedef std::map<uint64_t, T> underlyingt;
26
27public:
29 _size(0) {}
30
31 const T &operator[](uint64_t idx) const
32 {
33 INVARIANT(idx<_size, "index out of range");
34 return underlying[idx];
35 }
36
38 {
39 INVARIANT(idx<_size, "index out of range");
40 return underlying[idx];
41 }
42
43 uint64_t size() const
44 {
45 return _size;
46 }
47
49 {
50 INVARIANT(new_size>=_size, "sparse vector can't be shrunk (yet)");
52 }
53
54 void clear()
55 {
57 _size = 0;
58 }
59
60 typedef typename underlyingt::iterator iteratort;
61 typedef typename underlyingt::const_iterator const_iteratort;
62
63 iteratort begin() { return underlying.begin(); }
64 const_iteratort begin() const { return underlying.begin(); }
65
66 iteratort end() { return underlying.end(); }
67 const_iteratort end() const { return underlying.end(); }
68
69 const_iteratort find(uint64_t idx) { return underlying.find(idx); }
70};
71
72#endif // CPROVER_UTIL_SPARSE_VECTOR_H
virtual void clear()
Reset the abstract state.
Definition ai.h:265
ait supplies three of the four components needed: an abstract interpreter (in this case handling func...
Definition ai.h:562
const_iteratort find(uint64_t idx)
T & operator[](uint64_t idx)
const_iteratort begin() const
void resize(uint64_t new_size)
const T & operator[](uint64_t idx) const
underlyingt underlying
iteratort begin()
underlyingt::iterator iteratort
const_iteratort end() const
iteratort end()
underlyingt::const_iterator const_iteratort
uint64_t size() const
std::map< uint64_t, T > underlyingt
#define INVARIANT(CONDITION, REASON)
This macro uses the wrapper function 'invariant_violated_string'.
Definition invariant.h:423