fork download
  1. #ifndef LITB_HASHTABLE_H
  2. #define LITB_HASHTABLE_H
  3.  
  4. #include <type_traits>
  5. #include <utility>
  6.  
  7. namespace litb {
  8. // A pair similar to std::pair, but a bit simplier
  9. template<typename First, typename Second>
  10. struct Pair {
  11. Pair()
  12. :first(), second()
  13. { }
  14.  
  15. // for being able to construct us with non-deducible arguments
  16. // (e.g initializer lists)
  17. Pair(const First& first, const Second& second)
  18. :first(first), second(second)
  19. { }
  20.  
  21. // for moving first and second into us
  22. template<typename First1, typename Second1,
  23. typename std::enable_if<
  24. std::is_convertible<First1, First>::value &&
  25. std::is_convertible<Second1, Second>::value,
  26. int>::type = 0>
  27. Pair(First1&& first, Second1&& second)
  28. :first(std::forward<First1>(first)),
  29. second(std::forward<Second1>(second))
  30. { }
  31.  
  32. // converting constructors from convertible pairs
  33. template<typename First1, typename Second1>
  34. Pair(const Pair<First1, Second1>& other)
  35. :first(other.first), second(other.second)
  36. { }
  37.  
  38. // moving convertible pairs into us
  39. template<typename First1, typename Second1>
  40. Pair(Pair<First1, Second1>&& other)
  41. :first(std::move(other.first)),
  42. second(std::move(other.second))
  43. { }
  44.  
  45. // public, hence not prefixed by _
  46. First first;
  47. Second second;
  48. };
  49. }
  50.  
  51. namespace litb {
  52. template<typename T>
  53. T min(const T& a, const T& b) {
  54. return a < b ? a : b;
  55. }
  56.  
  57. template<typename T>
  58. T max(const T& a, const T& b) {
  59. return a > b ? a : b;
  60. }
  61.  
  62. // add the cv-qualifiers of MaybeCv to T
  63. template<typename T, typename MaybeCv>
  64. struct TransferCv {
  65. typedef T type;
  66. };
  67. template<typename T, typename MaybeCv>
  68. struct TransferCv<T, const MaybeCv> {
  69. typedef const T type;
  70. };
  71. template<typename T, typename MaybeCv>
  72. struct TransferCv<T, volatile MaybeCv> {
  73. typedef volatile T type;
  74. };
  75. template<typename T, typename MaybeCv>
  76. struct TransferCv<T, const volatile MaybeCv> {
  77. typedef const volatile T type;
  78. };
  79. }
  80.  
  81. #include <type_traits>
  82. #include <cstdint>
  83.  
  84. namespace litb {
  85. inline uint32_t hash(int n) { return n; }
  86. inline uint32_t hash(unsigned n) { return n; }
  87.  
  88. inline uint32_t hash(uint32_t n, std::true_type /* 32bit */) {
  89. return n;
  90. }
  91. inline uint32_t hash(uint64_t n, std::false_type /* 64bit */) {
  92. uint32_t n32 = (uint32_t)n;
  93. return n32 ^ (uint32_t)(n >> 32);
  94. }
  95.  
  96. inline uint32_t hash(unsigned long n) {
  97. return hash(n, std::integral_constant<bool, sizeof(unsigned long) == sizeof(uint32_t)>());
  98. }
  99. inline uint32_t hash(long n) {
  100. return hash((unsigned long)n);
  101. }
  102.  
  103. inline uint32_t hash(unsigned long long n) {
  104. return hash(n, std::false_type());
  105. }
  106. inline uint32_t hash(long long n) {
  107. return hash((unsigned long long)n);
  108. }
  109. }
  110.  
  111. #ifndef LITB_VECTOR_H
  112. #define LITB_VECTOR_H
  113.  
  114. #include <new>
  115. #include <type_traits>
  116.  
  117. namespace litb {
  118.  
  119. // The functionality of Vector that does not depend on the "SmallSize"
  120. // template parameter.
  121. //
  122. template<typename T>
  123. class VectorBase {
  124. public:
  125. typedef T *iterator;
  126. typedef const T *const_iterator;
  127. typedef T value_type;
  128.  
  129.  
  130. public:
  131. ~VectorBase() {
  132. clear();
  133. if(usesHeap()) {
  134. operator delete(_data);
  135. }
  136. }
  137.  
  138. public:
  139. iterator begin() { return _data; }
  140. iterator end() { return _endData; }
  141. const_iterator begin() const { return _data; }
  142. const_iterator end() const { return _endData; }
  143.  
  144. public:
  145. // returns a reference to the element at the given index
  146. T &at(int index) {
  147. return _data[index];
  148. }
  149.  
  150. const T& at(int index) const {
  151. return _data[index];
  152. }
  153.  
  154. T &operator[](int index) {
  155. return at(index);
  156. }
  157.  
  158. const T& operator[](int index) const {
  159. return at(index);
  160. }
  161.  
  162. // appends a new item to the back of the vector
  163. void append(const T& t) {
  164. insert(end(), t);
  165. }
  166.  
  167. void prepend(const T& t) {
  168. insert(begin(), t);
  169. }
  170.  
  171. // inserts a new item before the given iterator, and return
  172. // an iterator to the new item
  173. iterator insert(iterator it, const T& t) {
  174. it = grow(it, 1);
  175. new ((void*)it) T(t);
  176. _endData++;
  177. return it;
  178. }
  179.  
  180. // assigns the given range to this vector
  181. template<typename Iterator>
  182. void assign(Iterator b, Iterator e) {
  183. clear();
  184. insert(end(), b, e);
  185. }
  186.  
  187. // inserts the range [b, e) before iterator position "it", and return
  188. // a pointer to the first item inserted
  189. template<typename Iterator>
  190. iterator insert(iterator it, Iterator b, Iterator e) {
  191. it = grow(it, e - b);
  192. for(; b != e; b++, it++) {
  193. new ((void*)it) T(*b);
  194. _endData++;
  195. }
  196. return it;
  197. }
  198.  
  199. // returns true if the vector contains no elements
  200. bool isEmpty() const {
  201. return _data == _endData;
  202. }
  203.  
  204. bool empty() const {
  205. return isEmpty();
  206. }
  207.  
  208. // resizes the vector to be of the given size afterwards, initializing all
  209. // new elements by value initialization
  210. void resize(int newSize) {
  211. if(size() < newSize) {
  212. iterator it = grow(end(), newSize - size());
  213. for(; newSize > 0; newSize--, it++) {
  214. new ((void*)it) T();
  215. _endData++;
  216. }
  217. } else if(size() > newSize) {
  218. erase(end() - (size() - newSize), end());
  219. }
  220. }
  221.  
  222. // makes the vector have size() 0, without changing the capacity
  223. void clear() {
  224. for(; _endData != _data; _endData--) {
  225. _endData[-1].~T();
  226. }
  227. _endData = _data;
  228. }
  229.  
  230. // erases the portion [b, e) of the vector, without changing the capacity
  231. void erase(iterator b, iterator e) {
  232. if(b == e) {
  233. clear();
  234. return;
  235. }
  236.  
  237. for(; e != _endData; e++, b++) {
  238. *b = *e;
  239. }
  240. T *dptr = _endData;
  241. for(T *edptr = dptr - (e - b); dptr != edptr; dptr--)
  242. dptr->~T();
  243. _endData = dptr;
  244. }
  245.  
  246. // returns the actual size of the vector
  247. int size() const { return _endData - _data; }
  248.  
  249. // returns the reserved capacity of the vector that it can insert without
  250. // reallocating
  251. int capacity() const { return _endReserve - _data; }
  252.  
  253. // returns true if we use the heap memory currently.
  254. bool usesHeap() const { return (const void*)_data != (this + 1); }
  255.  
  256. // reserves space for at least "space" items
  257. void reserve(int space) {
  258. if(space <= capacity())
  259. return;
  260.  
  261. grow(end(), space - capacity());
  262. }
  263.  
  264. // simply uses the assign function
  265. VectorBase &operator=(const VectorBase& other) {
  266. if(this == &other)
  267. return *this;
  268. assign(other.begin(), other.end());
  269. return *this;
  270. }
  271.  
  272. protected:
  273. // VectorBase cannot be created on its own
  274. VectorBase(T *data, T *endData)
  275. :_data(data), _endData(data), _endReserve(endData)
  276. { }
  277.  
  278. private:
  279. // reserves space for "elements" items before iterator "it".
  280. // returns an iterator pointing at the first free slot.
  281. iterator grow(iterator it, int elements) {
  282. if(elements == 0)
  283. return it;
  284.  
  285. int index = it - begin();
  286. if((_endReserve - _endData) < elements) {
  287. // reallocate, leaving "elements" free slots at "index"
  288. int newCapacity = max(capacity() * 2, capacity() + elements);
  289. T *data1 = (T*)operator new(sizeof(T) * newCapacity);
  290. T *endData1 = data1;
  291. T *endReserve1 = data1 + newCapacity;
  292. for(T *data = _data; data != _endData; data++, endData1++) {
  293. if(data - _data == index) {
  294. endData1 += elements;
  295. }
  296. new ((void*)endData1) T(*data);
  297. }
  298.  
  299. for(; _endData != _data; _endData--)
  300. _endData[-1].~T();
  301. if(usesHeap()) {
  302. operator delete(_data);
  303. }
  304. _data = data1;
  305. _endData= endData1;
  306. _endReserve = endReserve1;
  307. } else if(it != end()) {
  308. T *endData1 = _endData, *endDataNew1 = _endData + elements;
  309. int newlyAllocated = min(elements, end() - it);
  310. for(; newlyAllocated > 0; newlyAllocated--, endDataNew1--, endData1--) {
  311. new ((void*)&endDataNew1[-1]) T(endData1[-1]);
  312. }
  313. for(; endData1 != it; endData1--, endDataNew1--) {
  314. endDataNew1[-1] = endData1[-1];
  315. }
  316.  
  317. // the hole should contain unconstructed items that the caller can placement-new into
  318. int dtorsInHole = min(elements, (end() - it));
  319. for(iterator itHole = it; dtorsInHole > 0; dtorsInHole--, itHole++)
  320. itHole->~T();
  321. }
  322. return begin() + index;
  323. }
  324.  
  325. private:
  326. T *_data;
  327. T *_endData;
  328. T *_endReserve;
  329. };
  330.  
  331. // A vector that allocates "SmallSize" elements in its own memory and
  332. // only if more elements are needed, reverts to heap memory.
  333. template<typename T, int SmallSize>
  334. class Vector : public VectorBase<T> {
  335. union {
  336. typename std::aligned_storage<sizeof(T), alignof(T)>::type
  337. _aligner;
  338. unsigned char _buffer[sizeof(T) * SmallSize];
  339. };
  340.  
  341. public:
  342. Vector():VectorBase<T>((T*)_buffer, (T*)_buffer + SmallSize) {}
  343. Vector(const Vector& other):Vector() {
  344. this->insert(this->end(), other.begin(), other.end());
  345. }
  346. template<int SmallSize1>
  347. Vector(const Vector<T, SmallSize1>& other):Vector() {
  348. this->insert(this->end(), other.begin(), other.end());
  349. }
  350. };
  351.  
  352. // A vector similar to std::vector.
  353. template<typename T>
  354. class DynamicVector : public VectorBase<T> {
  355. // this padding. VectorBase can then determine that its pointers do never
  356. // point to the in-object buffer (as it cound otherise happen if VectorBase and its
  357. // malloced buffer would be adjacent in memory).
  358. char padding;
  359.  
  360. public:
  361. DynamicVector():VectorBase<T>(nullptr, nullptr) {}
  362. DynamicVector(const DynamicVector& other):DynamicVector() {
  363. this->insert(this->end(), other.begin(), other.end());
  364. }
  365. };
  366.  
  367. }
  368.  
  369. #endif
  370.  
  371. #include <utility>
  372. #include <iterator>
  373. #include <cstdint>
  374.  
  375. namespace litb {
  376.  
  377. // A hash table mapping "Key" to "Value".
  378. // "Key" must provide a "hash" function that is
  379. // found by argument-dependent-lookup.
  380. template<typename Key, typename Value>
  381. class HashTable {
  382. struct Bucket;
  383.  
  384. template<typename BucketType>
  385. struct Iterator;
  386.  
  387. typedef Iterator<Bucket> iterator;
  388. typedef Iterator<const Bucket> const_iterator;
  389. typedef Pair<const Key, Value> value_type;
  390. typedef Key key_type;
  391. typedef Value mapped_type;
  392.  
  393. public:
  394. HashTable():_size() { _buckets.append((Bucket*)-1); }
  395. ~HashTable() {
  396. clear();
  397. }
  398.  
  399. iterator begin() { return iterator(_buckets.begin()); }
  400. iterator end() { return iterator(_buckets.end() - 1); }
  401. const_iterator begin() const { return const_iterator(_buckets.begin()); }
  402. const_iterator end() const { return const_iterator(_buckets.end() - 1); }
  403.  
  404. public:
  405. // returns the size (number of keys) of this table
  406. int size() const {
  407. return _size;
  408. }
  409.  
  410. // inserts the given mapping, returning false if the key was already mapped. in that case,
  411. // the value will not be updated.
  412. bool insert(const Pair<Key, Value>& mapping) {
  413. struct C {
  414. const Value &operator()() const {
  415. return value;
  416. }
  417. const Value& value;
  418. } creator = { mapping.second };
  419. return internalInsert(mapping.first, creator);
  420. }
  421.  
  422. // inserts a mapping of key to value.
  423. // returns true if the mapping was inserted, and false if the key was already
  424. // mapped. In that case, the value will not be updated.
  425. bool insert(const Key& key, const Value& value) {
  426. struct C {
  427. const Value &operator()() const {
  428. return value;
  429. }
  430. const Value& value;
  431. } creator = { value };
  432. return internalInsert(key, creator);
  433. }
  434.  
  435. // returns true if the table contains a mapping from key to a value
  436. bool contains(const Key& key) const {
  437. return getBucket(key) != nullptr;
  438. }
  439.  
  440. // returns a reference to the value mapped by the given key. If the element
  441. // does not exist yet, it is value-initialized and copied to the map.
  442. Value &at(const Key& key) {
  443. struct C {
  444. Value operator()() const {
  445. return Value();
  446. }
  447. } creator;
  448. return getOrCreateBucket(key, creator)->_data.second;
  449. }
  450.  
  451. Value &operator[](const Key& key) {
  452. return at(key);
  453. }
  454.  
  455. // if for this overload the element does not exist, behavior is undefined
  456. const Value& at(const Key& key) const {
  457. return getBucket(key)->_data.second;
  458. }
  459.  
  460. const Value& operator[](const Key& key) const {
  461. return at(key);
  462. }
  463.  
  464. // after calling this the map contains no elements anymore and the bucket array
  465. // is empty
  466. void clear() {
  467. for(auto it = _buckets.begin(), ite = _buckets.end()-1; it != ite; ++it) {
  468. Bucket *bucket = *it;
  469. while(bucket) {
  470. Bucket *bucket1 = bucket;
  471. delete bucket1;
  472. bucket = bucket->_next;
  473. }
  474. }
  475. _buckets.clear();
  476. _buckets.append((Bucket*)-1);
  477. _size = 0;
  478. }
  479.  
  480. // erases the item at the given position
  481. void erase(iterator it) {
  482. Bucket ** head = it._bucketHead;
  483. if(*head == it._bucket) {
  484. *head = (*head)->next;
  485. } else {
  486. Bucket *bucket = *head;
  487. for(; bucket->_next != it._bucket; bucket = bucket->_next)
  488. ;
  489. bucket->_next = it._bucket->next;
  490. }
  491. delete it._bucket;
  492. _size--;
  493. }
  494.  
  495. private:
  496. // one bucket in the buckets array
  497. struct Bucket {
  498. Bucket(const Key& key, const Value& value, Bucket *next)
  499. :_data(key, value), _next(next)
  500. { }
  501.  
  502. value_type _data;
  503. Bucket *_next;
  504. };
  505.  
  506. template<typename BucketType>
  507. struct Iterator {
  508. template<typename Key1, typename Value1>
  509. friend class HashTable;
  510.  
  511. typedef HashTable::value_type value_type;
  512. typedef typename TransferCv<value_type, BucketType>::type &reference_type;
  513. typedef typename TransferCv<value_type, BucketType>::type *pointer;
  514. typedef int difference_type;
  515. typedef std::forward_iterator_tag iterator_category;
  516.  
  517. Iterator(typename TransferCv<BucketType*, BucketType>::type *bucketHead)
  518. :_bucketHead(bucketHead)
  519. { alignToNextBucket(); }
  520.  
  521. public:
  522. friend bool operator==(const Iterator& a, const Iterator& b) {
  523. return a._bucket == b._bucket;
  524. }
  525.  
  526. friend bool operator!=(const Iterator& a, const Iterator& b) {
  527. return !(a == b);
  528. }
  529.  
  530. public:
  531. reference_type operator*() const {
  532. return _bucket->_data;
  533. }
  534.  
  535. pointer operator->() const {
  536. return &_bucket->_data;
  537. }
  538.  
  539. // convenience wrappers key() and value() return the key and the mapped data
  540. // respectively
  541. const key_type& key() const {
  542. return (*this)->first;
  543. }
  544.  
  545. typename TransferCv<mapped_type, BucketType>::type &value() const {
  546. return (*this)->second;
  547. }
  548.  
  549. public:
  550. Iterator operator++(int) {
  551. Iterator it(*this);
  552. ++it;
  553. return it;
  554. }
  555.  
  556. Iterator &operator++() {
  557. if(!_bucket->_next) {
  558. _bucketHead++;
  559. alignToNextBucket();
  560. } else {
  561. _bucket = _bucket->_next;
  562. }
  563. return *this;
  564. }
  565.  
  566. private:
  567. void alignToNextBucket() {
  568. while (!*_bucketHead && *_bucketHead != (Bucket*)-1) {
  569. _bucketHead++;
  570. }
  571. _bucket = *_bucketHead;
  572. }
  573.  
  574. typename TransferCv<BucketType*, BucketType>::type *_bucketHead;
  575. BucketType *_bucket;
  576. };
  577.  
  578. private:
  579. static uint32_t hash(const Key& key) {
  580. using litb::hash;
  581. return hash(key);
  582. }
  583.  
  584. template<typename Creator>
  585. bool internalInsert(const Key& key, const Creator& c) {
  586. int oldSize = size();
  587. Bucket *bucket = getOrCreateBucket(key, c);
  588. return size() != oldSize;
  589. }
  590.  
  591. // returns a bucket for the given key and value.
  592. // if not yet existing, call "creator()" to create and return a new
  593. // instance of the value.
  594. template<typename Creator>
  595. Bucket *getOrCreateBucket(const Key& key, const Creator& c) {
  596. if(_buckets.size() == 1) {
  597. _buckets.clear();
  598. _buckets.resize(32);
  599. _buckets.append((Bucket*)-1);
  600. } else {
  601. const float loadFactor = size() / (float)(_buckets.size() - 1);
  602. if(loadFactor > 0.75) {
  603. rehash();
  604. }
  605. }
  606.  
  607. int bucketIndex = hash(key) % (_buckets.size() - 1);
  608. Bucket *bucket = _buckets[bucketIndex];
  609. for(Bucket *bucket1 = bucket; bucket1; bucket1 = bucket1->_next) {
  610. if(bucket1->_data.first == key) {
  611. return bucket1;
  612. }
  613. }
  614. bucket = new Bucket(key, c(), bucket);
  615. _buckets[bucketIndex] = bucket;
  616. _size++;
  617. return bucket;
  618. }
  619.  
  620. // returns the bucket for the given key and nullptr if it is not found
  621. const Bucket *getBucket(const Key& key) const {
  622. if(_buckets.size() == 1)
  623. return nullptr;
  624.  
  625. int bucketIndex = hash(key) % (_buckets.size() - 1);
  626. const Bucket *bucket = _buckets[bucketIndex];
  627. for(const Bucket *bucket1 = bucket; bucket1; bucket1 = bucket1->_next) {
  628. if(bucket1->_data.first == key) {
  629. return bucket1;
  630. }
  631. }
  632. return nullptr;
  633. }
  634.  
  635. // this will reallocate the bucket array and rehash everything
  636. void rehash() {
  637. int newSize = (_buckets.size() - 1) * 2;
  638. Vector<Bucket*, 1> newBuckets;
  639. newBuckets.resize(newSize);
  640. for(auto it = _buckets.begin(), ite = _buckets.end()-1; it != ite; ++it) {
  641. Bucket *bucket = *it;
  642. while(bucket) {
  643. int bucketIndex = hash(bucket->_data.first) % newBuckets.size();
  644.  
  645. Bucket *bucket1 = bucket;
  646. bucket = bucket->_next;
  647. bucket1->_next = newBuckets[bucketIndex];
  648. newBuckets[bucketIndex] = bucket1;
  649. }
  650. }
  651. newBuckets.append((Bucket*)-1);
  652. _buckets = std::move(newBuckets);
  653. }
  654.  
  655. private:
  656. // the last bucket pointer of _buckets designates the end() position
  657. // and always has the value (Bucket*)-1
  658. Vector<Bucket*, 1> _buckets;
  659. int _size;
  660. };
  661. }
  662.  
  663. #endif
  664.  
  665. #include <iostream>
  666.  
  667. struct A {
  668. A():x(-1) {
  669. std::cout << "A()" << std::endl;
  670. }
  671.  
  672. A(int x):x(x) {
  673. std::cout << "A(" << x << ")" << std::endl;
  674. }
  675.  
  676. ~A() {
  677. std::cout << "~A(" << x << ")" << std::endl;
  678. }
  679.  
  680. A(A const& other):x(other.x) {
  681. std::cout << "A(A const&)(" << other.x << ")" << std::endl;
  682. }
  683.  
  684. int x;
  685. };
  686.  
  687. int main() {
  688. litb::HashTable<int, A> hashTable;
  689. for(int i = 0; i < 100; i++)
  690. hashTable[i] = A(i * 2);
  691.  
  692. std::cout << "\n";
  693. for(auto it = hashTable.begin(), ite = hashTable.end(); it != ite; ++it) {
  694. std::cout << "> (" << it->first << ") -> (" << it->second.x << ")\n";
  695. }
  696. }
  697.  
  698.  
Success #stdin #stdout 0s 2988KB
stdin
Standard input is empty
stdout
A()
A(A const&)(-1)
~A(-1)
A(0)
~A(0)
A()
A(A const&)(-1)
~A(-1)
A(2)
~A(2)
A()
A(A const&)(-1)
~A(-1)
A(4)
~A(4)
A()
A(A const&)(-1)
~A(-1)
A(6)
~A(6)
A()
A(A const&)(-1)
~A(-1)
A(8)
~A(8)
A()
A(A const&)(-1)
~A(-1)
A(10)
~A(10)
A()
A(A const&)(-1)
~A(-1)
A(12)
~A(12)
A()
A(A const&)(-1)
~A(-1)
A(14)
~A(14)
A()
A(A const&)(-1)
~A(-1)
A(16)
~A(16)
A()
A(A const&)(-1)
~A(-1)
A(18)
~A(18)
A()
A(A const&)(-1)
~A(-1)
A(20)
~A(20)
A()
A(A const&)(-1)
~A(-1)
A(22)
~A(22)
A()
A(A const&)(-1)
~A(-1)
A(24)
~A(24)
A()
A(A const&)(-1)
~A(-1)
A(26)
~A(26)
A()
A(A const&)(-1)
~A(-1)
A(28)
~A(28)
A()
A(A const&)(-1)
~A(-1)
A(30)
~A(30)
A()
A(A const&)(-1)
~A(-1)
A(32)
~A(32)
A()
A(A const&)(-1)
~A(-1)
A(34)
~A(34)
A()
A(A const&)(-1)
~A(-1)
A(36)
~A(36)
A()
A(A const&)(-1)
~A(-1)
A(38)
~A(38)
A()
A(A const&)(-1)
~A(-1)
A(40)
~A(40)
A()
A(A const&)(-1)
~A(-1)
A(42)
~A(42)
A()
A(A const&)(-1)
~A(-1)
A(44)
~A(44)
A()
A(A const&)(-1)
~A(-1)
A(46)
~A(46)
A()
A(A const&)(-1)
~A(-1)
A(48)
~A(48)
A()
A(A const&)(-1)
~A(-1)
A(50)
~A(50)
A()
A(A const&)(-1)
~A(-1)
A(52)
~A(52)
A()
A(A const&)(-1)
~A(-1)
A(54)
~A(54)
A()
A(A const&)(-1)
~A(-1)
A(56)
~A(56)
A()
A(A const&)(-1)
~A(-1)
A(58)
~A(58)
A()
A(A const&)(-1)
~A(-1)
A(60)
~A(60)
A()
A(A const&)(-1)
~A(-1)
A(62)
~A(62)
A()
A(A const&)(-1)
~A(-1)
A(64)
~A(64)
A()
A(A const&)(-1)
~A(-1)
A(66)
~A(66)
A()
A(A const&)(-1)
~A(-1)
A(68)
~A(68)
A()
A(A const&)(-1)
~A(-1)
A(70)
~A(70)
A()
A(A const&)(-1)
~A(-1)
A(72)
~A(72)
A()
A(A const&)(-1)
~A(-1)
A(74)
~A(74)
A()
A(A const&)(-1)
~A(-1)
A(76)
~A(76)
A()
A(A const&)(-1)
~A(-1)
A(78)
~A(78)
A()
A(A const&)(-1)
~A(-1)
A(80)
~A(80)
A()
A(A const&)(-1)
~A(-1)
A(82)
~A(82)
A()
A(A const&)(-1)
~A(-1)
A(84)
~A(84)
A()
A(A const&)(-1)
~A(-1)
A(86)
~A(86)
A()
A(A const&)(-1)
~A(-1)
A(88)
~A(88)
A()
A(A const&)(-1)
~A(-1)
A(90)
~A(90)
A()
A(A const&)(-1)
~A(-1)
A(92)
~A(92)
A()
A(A const&)(-1)
~A(-1)
A(94)
~A(94)
A()
A(A const&)(-1)
~A(-1)
A(96)
~A(96)
A()
A(A const&)(-1)
~A(-1)
A(98)
~A(98)
A()
A(A const&)(-1)
~A(-1)
A(100)
~A(100)
A()
A(A const&)(-1)
~A(-1)
A(102)
~A(102)
A()
A(A const&)(-1)
~A(-1)
A(104)
~A(104)
A()
A(A const&)(-1)
~A(-1)
A(106)
~A(106)
A()
A(A const&)(-1)
~A(-1)
A(108)
~A(108)
A()
A(A const&)(-1)
~A(-1)
A(110)
~A(110)
A()
A(A const&)(-1)
~A(-1)
A(112)
~A(112)
A()
A(A const&)(-1)
~A(-1)
A(114)
~A(114)
A()
A(A const&)(-1)
~A(-1)
A(116)
~A(116)
A()
A(A const&)(-1)
~A(-1)
A(118)
~A(118)
A()
A(A const&)(-1)
~A(-1)
A(120)
~A(120)
A()
A(A const&)(-1)
~A(-1)
A(122)
~A(122)
A()
A(A const&)(-1)
~A(-1)
A(124)
~A(124)
A()
A(A const&)(-1)
~A(-1)
A(126)
~A(126)
A()
A(A const&)(-1)
~A(-1)
A(128)
~A(128)
A()
A(A const&)(-1)
~A(-1)
A(130)
~A(130)
A()
A(A const&)(-1)
~A(-1)
A(132)
~A(132)
A()
A(A const&)(-1)
~A(-1)
A(134)
~A(134)
A()
A(A const&)(-1)
~A(-1)
A(136)
~A(136)
A()
A(A const&)(-1)
~A(-1)
A(138)
~A(138)
A()
A(A const&)(-1)
~A(-1)
A(140)
~A(140)
A()
A(A const&)(-1)
~A(-1)
A(142)
~A(142)
A()
A(A const&)(-1)
~A(-1)
A(144)
~A(144)
A()
A(A const&)(-1)
~A(-1)
A(146)
~A(146)
A()
A(A const&)(-1)
~A(-1)
A(148)
~A(148)
A()
A(A const&)(-1)
~A(-1)
A(150)
~A(150)
A()
A(A const&)(-1)
~A(-1)
A(152)
~A(152)
A()
A(A const&)(-1)
~A(-1)
A(154)
~A(154)
A()
A(A const&)(-1)
~A(-1)
A(156)
~A(156)
A()
A(A const&)(-1)
~A(-1)
A(158)
~A(158)
A()
A(A const&)(-1)
~A(-1)
A(160)
~A(160)
A()
A(A const&)(-1)
~A(-1)
A(162)
~A(162)
A()
A(A const&)(-1)
~A(-1)
A(164)
~A(164)
A()
A(A const&)(-1)
~A(-1)
A(166)
~A(166)
A()
A(A const&)(-1)
~A(-1)
A(168)
~A(168)
A()
A(A const&)(-1)
~A(-1)
A(170)
~A(170)
A()
A(A const&)(-1)
~A(-1)
A(172)
~A(172)
A()
A(A const&)(-1)
~A(-1)
A(174)
~A(174)
A()
A(A const&)(-1)
~A(-1)
A(176)
~A(176)
A()
A(A const&)(-1)
~A(-1)
A(178)
~A(178)
A()
A(A const&)(-1)
~A(-1)
A(180)
~A(180)
A()
A(A const&)(-1)
~A(-1)
A(182)
~A(182)
A()
A(A const&)(-1)
~A(-1)
A(184)
~A(184)
A()
A(A const&)(-1)
~A(-1)
A(186)
~A(186)
A()
A(A const&)(-1)
~A(-1)
A(188)
~A(188)
A()
A(A const&)(-1)
~A(-1)
A(190)
~A(190)
A()
A(A const&)(-1)
~A(-1)
A(192)
~A(192)
A()
A(A const&)(-1)
~A(-1)
A(194)
~A(194)
A()
A(A const&)(-1)
~A(-1)
A(196)
~A(196)
A()
A(A const&)(-1)
~A(-1)
A(198)
~A(198)

> (0) -> (0)
> (1) -> (2)
> (2) -> (4)
> (3) -> (6)
> (4) -> (8)
> (5) -> (10)
> (6) -> (12)
> (7) -> (14)
> (8) -> (16)
> (9) -> (18)
> (10) -> (20)
> (11) -> (22)
> (12) -> (24)
> (13) -> (26)
> (14) -> (28)
> (15) -> (30)
> (16) -> (32)
> (17) -> (34)
> (18) -> (36)
> (19) -> (38)
> (20) -> (40)
> (21) -> (42)
> (22) -> (44)
> (23) -> (46)
> (24) -> (48)
> (25) -> (50)
> (26) -> (52)
> (27) -> (54)
> (28) -> (56)
> (29) -> (58)
> (30) -> (60)
> (31) -> (62)
> (32) -> (64)
> (33) -> (66)
> (34) -> (68)
> (35) -> (70)
> (36) -> (72)
> (37) -> (74)
> (38) -> (76)
> (39) -> (78)
> (40) -> (80)
> (41) -> (82)
> (42) -> (84)
> (43) -> (86)
> (44) -> (88)
> (45) -> (90)
> (46) -> (92)
> (47) -> (94)
> (48) -> (96)
> (49) -> (98)
> (50) -> (100)
> (51) -> (102)
> (52) -> (104)
> (53) -> (106)
> (54) -> (108)
> (55) -> (110)
> (56) -> (112)
> (57) -> (114)
> (58) -> (116)
> (59) -> (118)
> (60) -> (120)
> (61) -> (122)
> (62) -> (124)
> (63) -> (126)
> (64) -> (128)
> (65) -> (130)
> (66) -> (132)
> (67) -> (134)
> (68) -> (136)
> (69) -> (138)
> (70) -> (140)
> (71) -> (142)
> (72) -> (144)
> (73) -> (146)
> (74) -> (148)
> (75) -> (150)
> (76) -> (152)
> (77) -> (154)
> (78) -> (156)
> (79) -> (158)
> (80) -> (160)
> (81) -> (162)
> (82) -> (164)
> (83) -> (166)
> (84) -> (168)
> (85) -> (170)
> (86) -> (172)
> (87) -> (174)
> (88) -> (176)
> (89) -> (178)
> (90) -> (180)
> (91) -> (182)
> (92) -> (184)
> (93) -> (186)
> (94) -> (188)
> (95) -> (190)
> (96) -> (192)
> (97) -> (194)
> (98) -> (196)
> (99) -> (198)
~A(0)
~A(2)
~A(4)
~A(6)
~A(8)
~A(10)
~A(12)
~A(14)
~A(16)
~A(18)
~A(20)
~A(22)
~A(24)
~A(26)
~A(28)
~A(30)
~A(32)
~A(34)
~A(36)
~A(38)
~A(40)
~A(42)
~A(44)
~A(46)
~A(48)
~A(50)
~A(52)
~A(54)
~A(56)
~A(58)
~A(60)
~A(62)
~A(64)
~A(66)
~A(68)
~A(70)
~A(72)
~A(74)
~A(76)
~A(78)
~A(80)
~A(82)
~A(84)
~A(86)
~A(88)
~A(90)
~A(92)
~A(94)
~A(96)
~A(98)
~A(100)
~A(102)
~A(104)
~A(106)
~A(108)
~A(110)
~A(112)
~A(114)
~A(116)
~A(118)
~A(120)
~A(122)
~A(124)
~A(126)
~A(128)
~A(130)
~A(132)
~A(134)
~A(136)
~A(138)
~A(140)
~A(142)
~A(144)
~A(146)
~A(148)
~A(150)
~A(152)
~A(154)
~A(156)
~A(158)
~A(160)
~A(162)
~A(164)
~A(166)
~A(168)
~A(170)
~A(172)
~A(174)
~A(176)
~A(178)
~A(180)
~A(182)
~A(184)
~A(186)
~A(188)
~A(190)
~A(192)
~A(194)
~A(196)
~A(198)