blob: 0e4d8212f21b99749f46d2cf6531c2dea0b163a2 [file] [log] [blame]
HYuana9b85752014-02-26 02:32:30 -06001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -07003 * Copyright (c) 2014 Regents of the University of California,
4 * Arizona Board of Regents,
5 * Colorado State University,
6 * University Pierre & Marie Curie, Sorbonne University,
7 * Washington University in St. Louis,
8 * Beijing Institute of Technology
9 *
10 * This file is part of NFD (Named Data Networking Forwarding Daemon).
11 * See AUTHORS.md for complete list of NFD authors and contributors.
12 *
13 * NFD is free software: you can redistribute it and/or modify it under the terms
14 * of the GNU General Public License as published by the Free Software Foundation,
15 * either version 3 of the License, or (at your option) any later version.
16 *
17 * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
18 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
19 * PURPOSE. See the GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License along with
22 * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
23 **/
HYuana9b85752014-02-26 02:32:30 -060024
25// Name Tree Entry (i.e., Name Prefix Entry)
26
27#include "name-tree-entry.hpp"
28
29namespace nfd {
30namespace name_tree {
31
Haowei Yuanf52dac72014-03-24 23:35:03 -050032Node::Node()
33 : m_prev(0)
34 , m_next(0)
HYuana9b85752014-02-26 02:32:30 -060035{
36}
37
38Node::~Node()
39{
40 // erase the Name Tree Nodes that were created to
41 // resolve hash collisions
42 // So before erasing a single node, make sure its m_next == 0
43 // See eraseEntryIfEmpty in name-tree.cpp
44 if (m_next)
45 delete m_next;
46}
47
Junxiao Shi9f7455b2014-04-07 21:02:16 -070048Entry::Entry(const Name& name)
49 : m_hash(0)
50 , m_prefix(name)
HYuana9b85752014-02-26 02:32:30 -060051{
52}
53
54Entry::~Entry()
55{
56}
57
58void
Junxiao Shi9f7455b2014-04-07 21:02:16 -070059Entry::erasePitEntry(shared_ptr<pit::Entry> pitEntry)
HYuana9b85752014-02-26 02:32:30 -060060{
Junxiao Shi9f7455b2014-04-07 21:02:16 -070061 BOOST_ASSERT(static_cast<bool>(pitEntry));
62 BOOST_ASSERT(pitEntry->m_nameTreeEntry.get() == this);
63
64 std::vector<shared_ptr<pit::Entry> >::iterator it =
65 std::find(m_pitEntries.begin(), m_pitEntries.end(), pitEntry);
66 BOOST_ASSERT(it != m_pitEntries.end());
67
68 *it = m_pitEntries.back();
69 m_pitEntries.pop_back();
70 pitEntry->m_nameTreeEntry.reset();
71}
72
HYuana9b85752014-02-26 02:32:30 -060073} // namespace name_tree
74} // namespace nfd