Luzhiled's Library

This documentation is automatically generated by online-judge-tools/verification-helper

View the Project on GitHub ei1333/library

:warning: structure/develop/array-pool.hpp

Code

template <class T, size_t V>
struct ArrayPool {
  array<T, V> pool;
  array<T *, V> stock;
  int ptr;

  ArrayPool() { clear(); }

  inline T *alloc() { return stock[--ptr]; }

  inline void free(T *t) { stock[ptr++] = t; }

  void clear() {
    ptr = (int)pool.size();
    for (int i = 0; i < pool.size(); i++) stock[i] = &pool[i];
  }
};
#line 1 "structure/develop/array-pool.hpp"
template <class T, size_t V>
struct ArrayPool {
  array<T, V> pool;
  array<T *, V> stock;
  int ptr;

  ArrayPool() { clear(); }

  inline T *alloc() { return stock[--ptr]; }

  inline void free(T *t) { stock[ptr++] = t; }

  void clear() {
    ptr = (int)pool.size();
    for (int i = 0; i < pool.size(); i++) stock[i] = &pool[i];
  }
};
Back to top page