/usr/include/polymake/Fibonacci.h is in polymake 3.0r1-4.
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 | /* Copyright (c) 1997-2015
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_FIBONACCI_H
#define POLYMAKE_FIBONACCI_H
#include "polymake/internal/iterators.h"
#include <limits>
namespace pm
{
template <typename Number=int> class FibonacciNumbers;
// An infinite source of Fibonacci numbers - as iterator
template <typename Number=int>
class Fibonacci_iterator {
public:
typedef forward_iterator_tag iterator_category;
typedef Number value_type;
typedef const Number& reference;
typedef const Number* pointer;
typedef ptrdiff_t difference_type;
typedef Fibonacci_iterator iterator;
typedef iterator const_iterator;
Fibonacci_iterator() : prev(0), cur(1) { }
reference operator* () const { return cur; }
pointer operator-> () const { return &cur; }
iterator& operator++ () { const Number p=prev; prev=cur; cur+=p; return *this; }
const iterator operator++ (int) { iterator copy(*this); operator++(); return copy; }
bool operator== (const iterator& it) const { return prev==it.prev && cur==it.cur; }
bool operator!= (const iterator& it) const { return !operator==(it); }
void rewind() { prev=0; cur=1; }
protected:
Number prev, cur;
Fibonacci_iterator(bool at_end) : prev(0), cur(0) { }
friend class FibonacciNumbers<Number>;
};
// An infinite source of Fibonacci numbers - as container
template <typename Number>
class FibonacciNumbers {
public:
typedef Number value_type;
typedef const Number& reference;
typedef reference const_reference;
typedef Fibonacci_iterator<Number> iterator;
typedef iterator const_iterator;
iterator begin() const { return iterator(); }
iterator end() const { return iterator(true); }
reference front() const { static Number one(1); return one; }
size_t size() const { return std::numeric_limits<size_t>::max(); }
bool empty() const { return false; }
};
template <typename Number>
struct check_iterator_feature<Fibonacci_iterator<Number>, unlimited> : True { };
template <typename Number>
struct check_iterator_feature<Fibonacci_iterator<Number>, rewindable> : True { };
template <typename Number>
struct spec_object_traits< FibonacciNumbers<Number> > : spec_object_traits<is_container> { };
template <typename Number> inline
Fibonacci_iterator<Number> fibonacci_numbers() { return Fibonacci_iterator<Number>(); }
inline
Fibonacci_iterator<> fibonacci_numbers() { return Fibonacci_iterator<>(); }
template <typename Number> inline
Number fibonacci_number(int i)
{
Fibonacci_iterator<Number> it;
while (--i>=0) ++it;
return *it;
}
inline int fibonacci_number(int i) { return fibonacci_number<int>(i); }
}
namespace polymake {
using pm::Fibonacci_iterator;
using pm::FibonacciNumbers;
using pm::fibonacci_numbers;
using pm::fibonacci_number;
}
#endif // POLYMAKE_FIBONACCI_H
// Local Variables:
// mode:C++
// c-basic-offset:3
// indent-tabs-mode:nil
// End:
|