/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
 * Copyright (c) 2014-2024,  Regents of the University of California,
 *                           Arizona Board of Regents,
 *                           Colorado State University,
 *                           University Pierre & Marie Curie, Sorbonne University,
 *                           Washington University in St. Louis,
 *                           Beijing Institute of Technology,
 *                           The University of Memphis.
 *
 * This file is part of NFD (Named Data Networking Forwarding Daemon).
 * See AUTHORS.md for complete list of NFD authors and contributors.
 *
 * NFD 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 3 of the License, or (at your option) any later version.
 *
 * NFD 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.
 *
 * You should have received a copy of the GNU General Public License along with
 * NFD, e.g., in COPYING.md file.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef NFD_DAEMON_TABLE_NAME_TREE_ITERATOR_HPP
#define NFD_DAEMON_TABLE_NAME_TREE_ITERATOR_HPP

#include "name-tree-hashtable.hpp"

#include <boost/operators.hpp>
#include <boost/range/iterator_range_core.hpp>

#include <functional>

namespace nfd::name_tree {

class NameTree;

/**
 * \brief A predicate to accept or reject an Entry in find operations.
 */
using EntrySelector = std::function<bool(const Entry&)>;

/**
 * \brief An #EntrySelector that accepts every Entry.
 */
struct AnyEntry
{
  constexpr bool
  operator()(const Entry&) const noexcept
  {
    return true;
  }
};

/** \brief A predicate to accept or reject an Entry and its children.
 *  \return `.first` indicates whether entry should be accepted;
 *          `.second` indicates whether entry's children should be visited
 */
using EntrySubTreeSelector = std::function<std::pair<bool, bool>(const Entry&)>;

/**
 * \brief An #EntrySubTreeSelector that accepts every Entry and its children.
 */
struct AnyEntrySubTree
{
  constexpr std::pair<bool, bool>
  operator()(const Entry&) const noexcept
  {
    return {true, true};
  }
};

class EnumerationImpl;

/**
 * \brief NameTree iterator.
 */
class Iterator : public boost::forward_iterator_helper<Iterator, const Entry>
{
public:
  Iterator();

  Iterator(shared_ptr<EnumerationImpl> impl, const Entry* ref);

  const Entry&
  operator*() const noexcept
  {
    BOOST_ASSERT(m_impl != nullptr);
    return *m_entry;
  }

  Iterator&
  operator++();

  friend bool
  operator==(const Iterator& lhs, const Iterator& rhs) noexcept
  {
    return lhs.m_entry == rhs.m_entry;
  }

private:
  /** \brief Enumeration implementation; nullptr for end iterator.
   */
  shared_ptr<EnumerationImpl> m_impl;

  /** \brief Current entry; nullptr for uninitialized iterator.
   */
  const Entry* m_entry = nullptr;

  /** \brief Reference entry used by enumeration implementation.
   */
  const Entry* m_ref = nullptr;

  /** \brief State used by enumeration implementation.
   */
  int m_state = 0;

  friend std::ostream& operator<<(std::ostream&, const Iterator&);
  friend class FullEnumerationImpl;
  friend class PartialEnumerationImpl;
  friend class PrefixMatchImpl;
};

std::ostream&
operator<<(std::ostream& os, const Iterator& i);

/**
 * \brief Enumeration operation implementation.
 */
class EnumerationImpl
{
public:
  explicit
  EnumerationImpl(const NameTree& nt);

  virtual void
  advance(Iterator& i) = 0;

protected:
  ~EnumerationImpl() = default;

protected:
  const NameTree& nt;
  const Hashtable& ht;
};

/**
 * \brief Full enumeration implementation.
 */
class FullEnumerationImpl final : public EnumerationImpl
{
public:
  FullEnumerationImpl(const NameTree& nt, const EntrySelector& pred);

  void
  advance(Iterator& i) final;

private:
  EntrySelector m_pred;
};

/**
 * \brief Partial enumeration implementation.
 *
 * Iterator::m_ref should be initialized to subtree root.
 * Iterator::m_state LSB indicates whether to visit children of m_entry.
 */
class PartialEnumerationImpl final : public EnumerationImpl
{
public:
  PartialEnumerationImpl(const NameTree& nt, const EntrySubTreeSelector& pred);

  void
  advance(Iterator& i) final;

private:
  EntrySubTreeSelector m_pred;
};

/**
 * \brief Partial enumeration implementation.
 *
 * Iterator::m_ref should be initialized to longest prefix matched entry.
 */
class PrefixMatchImpl final : public EnumerationImpl
{
public:
  PrefixMatchImpl(const NameTree& nt, const EntrySelector& pred);

private:
  void
  advance(Iterator& i) final;

private:
  EntrySelector m_pred;
};

/**
 * \brief A forward range of name tree entries.
 *
 * This type has `.begin()` and `.end()` methods which return Iterator.
 * This type is usable with range-based for loops.
 */
using Range = boost::iterator_range<Iterator>;

} // namespace nfd::name_tree

#endif // NFD_DAEMON_TABLE_NAME_TREE_ITERATOR_HPP
