#pragma once
#include <cstddef>
#include <functional>
#include <initializer_list>
#include <memory>
#include <utility>
namespace tiny {
template <class T>
struct vec {
using value_type = T;
using iterator = T*;
using const_iterator = const T*;
vec() = default;
std::size_t i = 0;
for (
const auto& v : il) buf_[i++] = v;
}
T* data()
noexcept {
return buf_.
get(); }
const T* data()
const noexcept {
return buf_.
get(); }
T* begin()
noexcept {
return buf_.
get(); }
T* end()
noexcept {
return buf_.
get() + n_; }
const T* begin()
const noexcept {
return buf_.
get(); }
const T* end()
const noexcept {
return buf_.
get() + n_; }
};
template <class T>
class flist {
struct node { T value; node* next; };
node* head_ = nullptr;
node* tail_ = nullptr;
public:
using value_type = T;
struct iterator {
node* p;
using pointer = T*; using reference = T&;
T& operator*() const { return p->value; }
iterator& operator++() { p = p->next; return *this; }
iterator operator++(int) { auto t = *this; p = p->next; return t; }
bool operator==(const iterator& o) const { return p == o.p; }
bool operator!=(const iterator& o) const { return p != o.p; }
};
using const_iterator = iterator;
flist() = default;
~flist() { while (head_) { node* n = head_->next; delete head_; head_ = n; } }
flist(const flist&) = delete;
flist& operator=(const flist&) = delete;
void push_back(const T& v) {
node* n = new node{v, nullptr};
if (!head_) head_ = n; else tail_->next = n;
tail_ = n; ++n_;
}
iterator begin() const noexcept { return {head_}; }
iterator end() const noexcept { return {nullptr}; }
};
template <class K, class Compare = std::less<K>>
class set {
public:
using key_type = K;
using value_type = K;
using key_compare = Compare;
using iterator = const K*;
using const_iterator = const K*;
set() = default;
void insert(const K& k) {
Compare cmp{};
while (i < n_ && cmp(buf_[i], k)) ++i;
if (i < n_ && !cmp(k, buf_[i])) return;
for (
std::size_t j = 0; j < i; ++j) fresh[j] = buf_[j];
fresh[i] = k;
for (
std::size_t j = i; j < n_; ++j) fresh[j + 1] = buf_[j];
}
const_iterator begin() const noexcept { return buf_.get(); }
const_iterator end() const noexcept { return buf_.get() + n_; }
private:
};
template <class K, class V, class Compare = std::less<K>>
class dict {
public:
using key_type = K;
using mapped_type = V;
using key_compare = Compare;
using iterator = value_type*;
using const_iterator = const value_type*;
dict() = default;
void emplace(const K& k, const V& v) {
Compare cmp{};
while (i < n_ && cmp(buf_[i].first, k)) {
new (&fresh[i]) value_type(buf_[i].first, buf_[i].second); ++i;
}
new (&fresh[i]) value_type(k, v);
new (&fresh[j + 1]) value_type(buf_[j].first, buf_[j].second);
}
iterator begin() noexcept { return buf_.get(); }
iterator end() noexcept { return buf_.get() + n_; }
const_iterator begin() const noexcept { return buf_.get(); }
const_iterator end() const noexcept { return buf_.get() + n_; }
private:
};
}