<commit_before>
#pragma once

#include <nstd/Debug.h>

template<typename T, typename V> class Map
{
private:
  struct Item;
public:
  class Iterator
  {
  public:
    Iterator() : item(0) {}
    const T& key() const {return item->key;}
    V& operator*() {return item->value;}
    const V& operator*() const {return item->value;}
    const V* operator->() const {return &item->value;}
    const Iterator& operator++() {item = item->next; return *this;}
    const Iterator& operator--() {item = item->prev; return *this;}
    bool operator==(const Iterator& other) const {return item == other.item;}
    bool operator!=(const Iterator& other) const {return item != other.item;}

  private:
    Item* item;
    
    Iterator(Item* item) : item(item) {}

    friend class Map;
  };
  
public:
  Map() : _end(&endItem), _begin(&endItem), _size(0), root(0)
  {
    endItem.parent = 0;
    endItem.prev = 0;
    endItem.next = 0;
  }

  const Iterator& begin() const {return _begin;}
  const Iterator& end() const {return _end;}

  const T& front() const {return _begin.item->value;}
  const T& back() const {return _end.item->prev->value;}

  T& front() {return _begin.item->value;}
  T& back() {return _end.item->prev->value;}

  Iterator removeFront() {return remove(_begin);}
  Iterator removeBack() {return remove(_end.item->prev);}

  size_t size() const {return _size;}
  bool_t isEmpty() const {return !root;}

  Iterator find(const T& key) const
  {
    for(Item* item = root; item; )
    {
      if(key > item->key)
      {
        item = item->right;
        continue;
      }
      else if(key < item->key)
      {
        item = item->left;
        continue;
      }
      else
        return item;
    }
    return _end;
  }<commit_msg>Map: Add clear method<commit_after>
#pragma once

#include <nstd/Debug.h>

template<typename T, typename V> class Map
{
private:
  struct Item;
public:
  class Iterator
  {
  public:
    Iterator() : item(0) {}
    const T& key() const {return item->key;}
    V& operator*() {return item->value;}
    const V& operator*() const {return item->value;}
    const V* operator->() const {return &item->value;}
    const Iterator& operator++() {item = item->next; return *this;}
    const Iterator& operator--() {item = item->prev; return *this;}
    bool operator==(const Iterator& other) const {return item == other.item;}
    bool operator!=(const Iterator& other) const {return item != other.item;}

  private:
    Item* item;
    
    Iterator(Item* item) : item(item) {}

    friend class Map;
  };
  
public:
  Map() : _end(&endItem), _begin(&endItem), _size(0), root(0)
  {
    endItem.parent = 0;
    endItem.prev = 0;
    endItem.next = 0;
  }

  ~Map()
  {
    clear();
    // todo: freeItem stuff
  }

  const Iterator& begin() const {return _begin;}
  const Iterator& end() const {return _end;}

  const T& front() const {return _begin.item->value;}
  const T& back() const {return _end.item->prev->value;}

  T& front() {return _begin.item->value;}
  T& back() {return _end.item->prev->value;}

  Iterator removeFront() {return remove(_begin);}
  Iterator removeBack() {return remove(_end.item->prev);}

  size_t size() const {return _size;}
  bool_t isEmpty() const {return !root;}

  void_t clear()
  {
    //for(Item* i = _begin.item, * end = &endItem; i != end; i = i->next)
    //{
    //  i->~Item();
    //  i->prev = freeItem;
    //  freeItem = i;
    //}
    // todo: freeItem stuff
    for(Item* i = _begin.item, * end = &endItem, *next; i != end; i = next)
    {
      next = i->next;
      i->~Item();
      delete i;
    }
    _begin.item = &endItem;
    endItem.prev = 0;
    _size = 0;
  }

  Iterator find(const T& key) const
  {
    for(Item* item = root; item; )
    {
      if(key > item->key)
      {
        item = item->right;
        continue;
      }
      else if(key < item->key)
      {
        item = item->left;
        continue;
      }
      else
        return item;
    }
    return _end;
  }
{'fraction_non_alphanumeric': 0.1611362493715435, 'fraction_numerical': 0.003519356460532931, 'mean_word_length': 2.6238615664845173, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 50, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3579321', 'n_tokens_mistral': 1379, 'n_tokens_neox': 1339, 'n_words': 384}