/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
 * Copyright (c) 2014-2016,  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_HASHTABLE_HPP
#define NFD_DAEMON_TABLE_NAME_TREE_HASHTABLE_HPP

#include "core/common.hpp"

namespace nfd {
namespace name_tree {

class Entry;

/** \brief a single hash value
 */
typedef size_t HashValue;

/** \brief a sequence of hash values
 *  \sa computeHashes
 */
typedef std::vector<HashValue> HashSequence;

/** \brief computes a single hash value
 *  \param name base name
 *  \param prefixLen if non-negative, compute hash value for name.getPrefix(prefixLen);
 *                   if negative, compute hash value for complete name
 */
HashValue
computeHash(const Name& name, ssize_t prefixLen = -1);

/** \brief computes hash values for each prefix of name
 *  \return a hash sequence, where the i-th hash value equals computeHash(name, i)
 */
HashSequence
computeHashes(const Name& name);

/** \brief a hashtable node
 *
 *  Zero or more nodes can be added to a hashtable bucket. They are organized as
 *  a doubly linked list through prev and next pointers.
 */
class Node
{
public:
  /** \post entry != nullptr && entry->getName() == name
   */
  Node(HashValue h, const Name& name);

  /** \pre prev == nullptr
   *  \pre next == nullptr
   */
  ~Node();

public:
  HashValue hash;
  Node* prev;
  Node* next;
  shared_ptr<Entry> entry; /// \todo #3687 make Node sole owner of Entry
};

/** \return node associated with entry
 *  \note This function is for NameTree internal use.
 */
Node*
getNode(const Entry& entry);

/** \brief invoke a function for each node in a doubly linked list
 *  \tparam N either Node or const Node
 *  \tparam F a functor with signature void F(N*)
 *  \note It's safe to delete the node in the function.
 */
template<typename N, typename F>
void
foreachNode(N* head, const F& func)
{
  N* node = head;
  while (node != nullptr) {
    N* next = node->next;
    func(node);
    node = next;
  }
}

/** \brief provides options for Hashtable
 */
class HashtableOptions
{
public:
  /** \brief constructor
   *  \post initialSize == size
   *  \post minSize == size
   */
  explicit
  HashtableOptions(size_t size = 16);

public:
  /** \brief initial number of buckets
   */
  size_t initialSize;

  /** \brief minimal number of buckets
   */
  size_t minSize;

  /** \brief if hashtable has more than nBuckets*expandLoadFactor nodes, it will be expanded
   */
  float expandLoadFactor = 0.5;

  /** \brief when hashtable is expanded, its new size is nBuckets*expandFactor
   */
  float expandFactor = 2.0;

  /** \brief if hashtable has less than nBuckets*shrinkLoadFactor nodes, it will be shrunk
   */
  float shrinkLoadFactor = 0.1;

  /** \brief when hashtable is shrunk, its new size is max(nBuckets*shrinkFactor, minSize)
   */
  float shrinkFactor = 0.5;
};

/** \brief a hashtable for fast exact name lookup
 *
 *  The Hashtable contains a number of buckets.
 *  Each node is placed into a bucket determined by a hash value computed from its name.
 *  Hash collision is resolved through a doubly linked list in each bucket.
 *  The number of buckets is adjusted according to how many nodes are stored.
 */
class Hashtable
{
public:
  typedef HashtableOptions Options;

  explicit
  Hashtable(const Options& options);

  /** \brief deallocates all nodes
   */
  ~Hashtable();

  /** \return number of nodes
   */
  size_t
  size() const
  {
    return m_size;
  }

  /** \return number of buckets
   */
  size_t
  getNBuckets() const
  {
    return m_buckets.size();
  }

  /** \return bucket index for hash value h
   */
  size_t
  computeBucketIndex(HashValue h) const
  {
    return h % this->getNBuckets();
  }

  /** \return i-th bucket
   *  \pre bucket < getNBuckets()
   */
  const Node*
  getBucket(size_t bucket) const
  {
    BOOST_ASSERT(bucket < this->getNBuckets());
    return m_buckets[bucket]; // don't use m_bucket.at() for better performance
  }

  /** \brief find node for name.getPrefix(prefixLen)
   *  \pre name.size() > prefixLen
   */
  const Node*
  find(const Name& name, size_t prefixLen) const;

  /** \brief find node for name.getPrefix(prefixLen)
   *  \pre name.size() > prefixLen
   *  \pre hashes == computeHashes(name)
   */
  const Node*
  find(const Name& name, size_t prefixLen, const HashSequence& hashes) const;

  /** \brief find or insert node for name.getPrefix(prefixLen)
   *  \pre name.size() > prefixLen
   *  \pre hashes == computeHashes(name)
   */
  std::pair<const Node*, bool>
  insert(const Name& name, size_t prefixLen, const HashSequence& hashes);

  /** \brief delete node
   *  \pre node exists in this hashtable
   */
  void
  erase(Node* node);

private:
  /** \brief attach node to bucket
   */
  void
  attach(size_t bucket, Node* node);

  /** \brief detach node from bucket
   */
  void
  detach(size_t bucket, Node* node);

  std::pair<const Node*, bool>
  findOrInsert(const Name& name, size_t prefixLen, HashValue h, bool allowInsert);

  void
  computeThresholds();

  void
  resize(size_t newNBuckets);

private:
  std::vector<Node*> m_buckets;
  Options m_options;
  size_t m_size;
  size_t m_expandThreshold;
  size_t m_shrinkThreshold;
};

} // namespace name_tree
} // namespace nfd

#endif // NFD_DAEMON_TABLE_NAME_TREE_HASHTABLE_HPP
