/usr/include/polymake/internal/IndexDispenser.h is in libpolymake-dev-common 3.2r2-3.
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 | /* Copyright (c) 1997-2018
Ewgenij Gawrilow, Michael Joswig (Technische Universitaet Berlin, Germany)
http://www.polymake.org
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2, or (at your option) any
later version: http://www.gnu.org/licenses/gpl.txt.
This program 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 General Public License for more details.
--------------------------------------------------------------------------------
*/
#ifndef POLYMAKE_INTERNAL_INDEX_DISPENSER_H
#define POLYMAKE_INTERNAL_INDEX_DISPENSER_H
#include "polymake/internal/iterators.h"
#include "polymake/vector"
#include <cassert>
namespace pm {
template <typename Traits>
class IndexDispenser : protected Traits {
std::vector<int> indices;
int start, first_free;
void init(int reserve_size)
{
if (reserve_size) {
copy_range(entire(sequence(1, reserve_size-1)), indices.begin());
indices.back()=-1;
first_free=0;
} else {
first_free=-1;
}
}
int lease()
{
if (first_free<0) {
first_free=indices.size();
indices.push_back(-1);
Traits::resize(first_free+start+1);
}
int i=first_free;
first_free=indices[i];
return i+start;
}
void reclaim(int i)
{
i-=start;
indices[i]=first_free;
first_free=i;
}
public:
explicit IndexDispenser(int start_arg=0, int reserve_size=0)
: indices(reserve_size), start(start_arg)
{
assert(reserve_size>=0);
init(reserve_size);
}
IndexDispenser(const Traits& super_arg, int start_arg=0, int reserve_size=0)
: Traits(super_arg), indices(reserve_size), start(start_arg)
{
assert(reserve_size>=0);
init(reserve_size);
}
void clear(int new_start=0, int new_size=0)
{
indices.resize(new_size);
start=new_start;
init(new_size);
}
class agent {
mutable IndexDispenser *master;
int i;
friend class IndexDispenser;
agent(IndexDispenser& m)
: master(&m)
{
i=m.lease();
}
public:
agent() : master(0) { }
operator int() const { return i; }
agent& operator= (IndexDispenser& m)
{
if (master) master->reclaim(i);
master=&m;
i=m.lease();
return *this;
}
agent& operator= (const agent& other)
{
master=other.master; i=other.i;
other.master=NULL;
}
~agent() { if (master) master->reclaim(i); }
};
agent get() { return *this; }
};
} // end namespace pm
namespace polymake {
using pm::IndexDispenser;
}
#endif // POLYMAKE_INTERNAL_INDEX_DISPENSER_H
// Local Variables:
// mode:C++
// c-basic-offset:3
// indent-tabs-mode:nil
// End:
|