111cd02dfb91661c65134cac258cf5924270e9d2Dan Albert// -*- C++ -*- 211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 311cd02dfb91661c65134cac258cf5924270e9d2Dan Albert// Copyright (C) 2005-2014 Free Software Foundation, Inc. 411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert// 511cd02dfb91661c65134cac258cf5924270e9d2Dan Albert// This file is part of the GNU ISO C++ Library. This library is free 611cd02dfb91661c65134cac258cf5924270e9d2Dan Albert// software; you can redistribute it and/or modify it under the terms 711cd02dfb91661c65134cac258cf5924270e9d2Dan Albert// of the GNU General Public License as published by the Free Software 811cd02dfb91661c65134cac258cf5924270e9d2Dan Albert// Foundation; either version 3, or (at your option) any later 911cd02dfb91661c65134cac258cf5924270e9d2Dan Albert// version. 1011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 1111cd02dfb91661c65134cac258cf5924270e9d2Dan Albert// This library is distributed in the hope that it will be useful, but 1211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert// WITHOUT ANY WARRANTY; without even the implied warranty of 1311cd02dfb91661c65134cac258cf5924270e9d2Dan Albert// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 1411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert// General Public License for more details. 1511cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 1611cd02dfb91661c65134cac258cf5924270e9d2Dan Albert// Under Section 7 of GPL version 3, you are granted additional 1711cd02dfb91661c65134cac258cf5924270e9d2Dan Albert// permissions described in the GCC Runtime Library Exception, version 1811cd02dfb91661c65134cac258cf5924270e9d2Dan Albert// 3.1, as published by the Free Software Foundation. 1911cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 2011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert// You should have received a copy of the GNU General Public License and 2111cd02dfb91661c65134cac258cf5924270e9d2Dan Albert// a copy of the GCC Runtime Library Exception along with this program; 2211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see 2311cd02dfb91661c65134cac258cf5924270e9d2Dan Albert// <http://www.gnu.org/licenses/>. 2411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 2511cd02dfb91661c65134cac258cf5924270e9d2Dan Albert// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. 2611cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 2711cd02dfb91661c65134cac258cf5924270e9d2Dan Albert// Permission to use, copy, modify, sell, and distribute this software 2811cd02dfb91661c65134cac258cf5924270e9d2Dan Albert// is hereby granted without fee, provided that the above copyright 2911cd02dfb91661c65134cac258cf5924270e9d2Dan Albert// notice appears in all copies, and that both that copyright notice 3011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert// and this permission notice appear in supporting documentation. None 3111cd02dfb91661c65134cac258cf5924270e9d2Dan Albert// of the above authors, nor IBM Haifa Research Laboratories, make any 3211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert// representation about the suitability of this software for any 3311cd02dfb91661c65134cac258cf5924270e9d2Dan Albert// purpose. It is provided "as is" without express or implied 3411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert// warranty. 3511cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 3611cd02dfb91661c65134cac258cf5924270e9d2Dan Albert/** 3711cd02dfb91661c65134cac258cf5924270e9d2Dan Albert * @file splay_tree_/find_fn_imps.hpp 3811cd02dfb91661c65134cac258cf5924270e9d2Dan Albert * Contains an implementation class for splay_tree_. 3911cd02dfb91661c65134cac258cf5924270e9d2Dan Albert */ 4011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 4111cd02dfb91661c65134cac258cf5924270e9d2Dan AlbertPB_DS_CLASS_T_DEC 4211cd02dfb91661c65134cac258cf5924270e9d2Dan Albertinline typename PB_DS_CLASS_C_DEC::point_iterator 4311cd02dfb91661c65134cac258cf5924270e9d2Dan AlbertPB_DS_CLASS_C_DEC:: 4411cd02dfb91661c65134cac258cf5924270e9d2Dan Albertfind(key_const_reference r_key) 4511cd02dfb91661c65134cac258cf5924270e9d2Dan Albert{ 4611cd02dfb91661c65134cac258cf5924270e9d2Dan Albert node_pointer p_found = find_imp(r_key); 4711cd02dfb91661c65134cac258cf5924270e9d2Dan Albert if (p_found != base_type::m_p_head) 4811cd02dfb91661c65134cac258cf5924270e9d2Dan Albert splay(p_found); 4911cd02dfb91661c65134cac258cf5924270e9d2Dan Albert return point_iterator(p_found); 5011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert} 5111cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 5211cd02dfb91661c65134cac258cf5924270e9d2Dan AlbertPB_DS_CLASS_T_DEC 5311cd02dfb91661c65134cac258cf5924270e9d2Dan Albertinline typename PB_DS_CLASS_C_DEC::point_const_iterator 5411cd02dfb91661c65134cac258cf5924270e9d2Dan AlbertPB_DS_CLASS_C_DEC:: 5511cd02dfb91661c65134cac258cf5924270e9d2Dan Albertfind(key_const_reference r_key) const 5611cd02dfb91661c65134cac258cf5924270e9d2Dan Albert{ 5711cd02dfb91661c65134cac258cf5924270e9d2Dan Albert const node_pointer p_found = find_imp(r_key); 5811cd02dfb91661c65134cac258cf5924270e9d2Dan Albert if (p_found != base_type::m_p_head) 5911cd02dfb91661c65134cac258cf5924270e9d2Dan Albert const_cast<PB_DS_CLASS_C_DEC* >(this)->splay(p_found); 6011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert return point_iterator(p_found); 6111cd02dfb91661c65134cac258cf5924270e9d2Dan Albert} 6211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 6311cd02dfb91661c65134cac258cf5924270e9d2Dan AlbertPB_DS_CLASS_T_DEC 6411cd02dfb91661c65134cac258cf5924270e9d2Dan Albertinline typename PB_DS_CLASS_C_DEC::node_pointer 6511cd02dfb91661c65134cac258cf5924270e9d2Dan AlbertPB_DS_CLASS_C_DEC:: 6611cd02dfb91661c65134cac258cf5924270e9d2Dan Albertfind_imp(key_const_reference r_key) 6711cd02dfb91661c65134cac258cf5924270e9d2Dan Albert{ 6811cd02dfb91661c65134cac258cf5924270e9d2Dan Albert _GLIBCXX_DEBUG_ONLY(base_type::structure_only_assert_valid(__FILE__, 6911cd02dfb91661c65134cac258cf5924270e9d2Dan Albert __LINE__);) 7011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert node_pointer p_nd = base_type::m_p_head->m_p_parent; 7111cd02dfb91661c65134cac258cf5924270e9d2Dan Albert while (p_nd != 0) 7211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert if (!Cmp_Fn::operator()(PB_DS_V2F(p_nd->m_value), r_key)) 7311cd02dfb91661c65134cac258cf5924270e9d2Dan Albert { 7411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert if (!Cmp_Fn::operator()(r_key, PB_DS_V2F(p_nd->m_value))) 7511cd02dfb91661c65134cac258cf5924270e9d2Dan Albert return p_nd; 7611cd02dfb91661c65134cac258cf5924270e9d2Dan Albert p_nd = p_nd->m_p_left; 7711cd02dfb91661c65134cac258cf5924270e9d2Dan Albert } 7811cd02dfb91661c65134cac258cf5924270e9d2Dan Albert else 7911cd02dfb91661c65134cac258cf5924270e9d2Dan Albert p_nd = p_nd->m_p_right; 8011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert return base_type::m_p_head; 8111cd02dfb91661c65134cac258cf5924270e9d2Dan Albert} 8211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 8311cd02dfb91661c65134cac258cf5924270e9d2Dan AlbertPB_DS_CLASS_T_DEC 8411cd02dfb91661c65134cac258cf5924270e9d2Dan Albertinline const typename PB_DS_CLASS_C_DEC::node_pointer 8511cd02dfb91661c65134cac258cf5924270e9d2Dan AlbertPB_DS_CLASS_C_DEC:: 8611cd02dfb91661c65134cac258cf5924270e9d2Dan Albertfind_imp(key_const_reference r_key) const 8711cd02dfb91661c65134cac258cf5924270e9d2Dan Albert{ 8811cd02dfb91661c65134cac258cf5924270e9d2Dan Albert PB_DS_ASSERT_VALID((*this)) 8911cd02dfb91661c65134cac258cf5924270e9d2Dan Albert node_pointer p_nd = base_type::m_p_head->m_p_parent; 9011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert while (p_nd != 0) 9111cd02dfb91661c65134cac258cf5924270e9d2Dan Albert if (!Cmp_Fn::operator()(PB_DS_V2F(p_nd->m_value), r_key)) 9211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert { 9311cd02dfb91661c65134cac258cf5924270e9d2Dan Albert if (!Cmp_Fn::operator()(r_key, PB_DS_V2F(p_nd->m_value))) 9411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert return p_nd; 9511cd02dfb91661c65134cac258cf5924270e9d2Dan Albert p_nd = p_nd->m_p_left; 9611cd02dfb91661c65134cac258cf5924270e9d2Dan Albert } 9711cd02dfb91661c65134cac258cf5924270e9d2Dan Albert else 9811cd02dfb91661c65134cac258cf5924270e9d2Dan Albert p_nd = p_nd->m_p_right; 9911cd02dfb91661c65134cac258cf5924270e9d2Dan Albert return base_type::m_p_head; 10011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert} 101