1169691Skan// -*- C++ -*- 2169691Skan 3169691Skan// Copyright (C) 2005, 2006 Free Software Foundation, Inc. 4169691Skan// 5169691Skan// This file is part of the GNU ISO C++ Library. This library is free 6169691Skan// software; you can redistribute it and/or modify it under the terms 7169691Skan// of the GNU General Public License as published by the Free Software 8169691Skan// Foundation; either version 2, or (at your option) any later 9169691Skan// version. 10169691Skan 11169691Skan// This library is distributed in the hope that it will be useful, but 12169691Skan// WITHOUT ANY WARRANTY; without even the implied warranty of 13169691Skan// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14169691Skan// General Public License for more details. 15169691Skan 16169691Skan// You should have received a copy of the GNU General Public License 17169691Skan// along with this library; see the file COPYING. If not, write to 18169691Skan// the Free Software Foundation, 59 Temple Place - Suite 330, Boston, 19169691Skan// MA 02111-1307, USA. 20169691Skan 21169691Skan// As a special exception, you may use this file as part of a free 22169691Skan// software library without restriction. Specifically, if other files 23169691Skan// instantiate templates or use macros or inline functions from this 24169691Skan// file, or you compile this file and link it with other files to 25169691Skan// produce an executable, this file does not by itself cause the 26169691Skan// resulting executable to be covered by the GNU General Public 27169691Skan// License. This exception does not however invalidate any other 28169691Skan// reasons why the executable file might be covered by the GNU General 29169691Skan// Public License. 30169691Skan 31169691Skan// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. 32169691Skan 33169691Skan// Permission to use, copy, modify, sell, and distribute this software 34169691Skan// is hereby granted without fee, provided that the above copyright 35169691Skan// notice appears in all copies, and that both that copyright notice 36169691Skan// and this permission notice appear in supporting documentation. None 37169691Skan// of the above authors, nor IBM Haifa Research Laboratories, make any 38169691Skan// representation about the suitability of this software for any 39169691Skan// purpose. It is provided "as is" without express or implied 40169691Skan// warranty. 41169691Skan 42169691Skan/** 43169691Skan * @file tree_policy.hpp 44169691Skan * Contains tree-related policies. 45169691Skan */ 46169691Skan 47169691Skan#ifndef PB_DS_TREE_POLICY_HPP 48169691Skan#define PB_DS_TREE_POLICY_HPP 49169691Skan 50169691Skan#include <iterator> 51169691Skan#include <ext/pb_ds/detail/type_utils.hpp> 52169691Skan#include <ext/pb_ds/detail/basic_tree_policy/basic_tree_policy_base.hpp> 53169691Skan 54169691Skannamespace pb_ds 55169691Skan{ 56169691Skan // A null node updator, indicating that no node updates are required. 57169691Skan template<typename Const_Node_Iterator, 58169691Skan typename Node_Iterator, 59169691Skan typename Cmp_Fn, 60169691Skan typename Allocator> 61169691Skan struct null_tree_node_update 62169691Skan { }; 63169691Skan 64169691Skan#define PB_DS_CLASS_T_DEC \ 65169691Skan template<typename Const_Node_Iterator, class Node_Iterator, class Cmp_Fn, class Allocator> 66169691Skan 67169691Skan#define PB_DS_CLASS_C_DEC \ 68169691Skan tree_order_statistics_node_update<Const_Node_Iterator, Node_Iterator, Cmp_Fn, Allocator> 69169691Skan 70169691Skan#define PB_DS_BASE_C_DEC \ 71169691Skan detail::basic_tree_policy_base<Const_Node_Iterator, Node_Iterator, Allocator> 72169691Skan 73169691Skan // Functor updating ranks of entrees. 74169691Skan template<typename Const_Node_Iterator, typename Node_Iterator, 75169691Skan typename Cmp_Fn, typename Allocator> 76169691Skan class tree_order_statistics_node_update : private PB_DS_BASE_C_DEC 77169691Skan { 78169691Skan private: 79169691Skan typedef PB_DS_BASE_C_DEC base_type; 80169691Skan 81169691Skan public: 82169691Skan typedef Cmp_Fn cmp_fn; 83169691Skan typedef Allocator allocator; 84169691Skan typedef typename allocator::size_type size_type; 85169691Skan typedef typename base_type::key_type key_type; 86169691Skan typedef typename base_type::const_key_reference const_key_reference; 87169691Skan 88169691Skan typedef size_type metadata_type; 89169691Skan typedef Const_Node_Iterator const_node_iterator; 90169691Skan typedef Node_Iterator node_iterator; 91169691Skan typedef typename const_node_iterator::value_type const_iterator; 92169691Skan typedef typename node_iterator::value_type iterator; 93169691Skan 94169691Skan // Finds an entry by __order. Returns a const_iterator to the 95169691Skan // entry with the __order order, or a const_iterator to the 96169691Skan // container object's end if order is at least the size of the 97169691Skan // container object. 98169691Skan inline const_iterator 99169691Skan find_by_order(size_type order) const; 100169691Skan 101169691Skan // Finds an entry by __order. Returns an iterator to the entry 102169691Skan // with the __order order, or an iterator to the container 103169691Skan // object's end if order is at least the size of the container 104169691Skan // object. 105169691Skan inline iterator 106169691Skan find_by_order(size_type order); 107169691Skan 108169691Skan // Returns the order of a key within a sequence. For exapmle, if 109169691Skan // r_key is the smallest key, this method will return 0; if r_key 110169691Skan // is a key between the smallest and next key, this method will 111169691Skan // return 1; if r_key is a key larger than the largest key, this 112169691Skan // method will return the size of r_c. 113169691Skan inline size_type 114169691Skan order_of_key(const_key_reference r_key) const; 115169691Skan 116169691Skan private: 117169691Skan // Const reference to the container's value-type. 118169691Skan typedef typename base_type::const_reference const_reference; 119169691Skan 120169691Skan // Const pointer to the container's value-type. 121169691Skan typedef typename base_type::const_pointer const_pointer; 122169691Skan 123169691Skan typedef typename allocator::template rebind<metadata_type>::other metadata_rebind; 124169691Skan // Const metadata reference. 125169691Skan typedef typename metadata_rebind::const_reference const_metadata_reference; 126169691Skan 127169691Skan // Metadata reference. 128169691Skan typedef typename metadata_rebind::reference metadata_reference; 129169691Skan 130169691Skan // Returns the const_node_iterator associated with the tree's root node. 131169691Skan virtual const_node_iterator 132169691Skan node_begin() const = 0; 133169691Skan 134169691Skan // Returns the node_iterator associated with the tree's root node. 135169691Skan virtual node_iterator 136169691Skan node_begin() = 0; 137169691Skan 138169691Skan // Returns the const_node_iterator associated with a just-after leaf node. 139169691Skan virtual const_node_iterator 140169691Skan node_end() const = 0; 141169691Skan 142169691Skan // Returns the node_iterator associated with a just-after leaf node. 143169691Skan virtual node_iterator 144169691Skan node_end() = 0; 145169691Skan 146169691Skan // Access to the cmp_fn object. 147169691Skan virtual cmp_fn& 148169691Skan get_cmp_fn() = 0; 149169691Skan 150169691Skan protected: 151169691Skan // Updates the rank of a node through a node_iterator node_it; 152169691Skan // end_nd_it is the end node iterator. 153169691Skan inline void 154169691Skan operator()(node_iterator node_it, const_node_iterator end_nd_it) const; 155169691Skan 156169691Skan virtual 157169691Skan ~tree_order_statistics_node_update(); 158169691Skan }; 159169691Skan 160169691Skan#include <ext/pb_ds/detail/tree_policy/order_statistics_imp.hpp> 161169691Skan 162169691Skan#undef PB_DS_CLASS_T_DEC 163169691Skan#undef PB_DS_CLASS_C_DEC 164169691Skan#undef PB_DS_BASE_C_DEC 165169691Skan 166169691Skan} // namespace pb_ds 167169691Skan 168169691Skan#endif 169