11573Srgrimes// -*- C++ -*- 21573Srgrimes 31573Srgrimes// Copyright (C) 2005, 2006 Free Software Foundation, Inc. 41573Srgrimes// 51573Srgrimes// This file is part of the GNU ISO C++ Library. This library is free 61573Srgrimes// software; you can redistribute it and/or modify it under the terms 71573Srgrimes// of the GNU General Public License as published by the Free Software 81573Srgrimes// Foundation; either version 2, or (at your option) any later 91573Srgrimes// version. 101573Srgrimes 111573Srgrimes// This library is distributed in the hope that it will be useful, but 121573Srgrimes// WITHOUT ANY WARRANTY; without even the implied warranty of 131573Srgrimes// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 141573Srgrimes// General Public License for more details. 151573Srgrimes 161573Srgrimes// You should have received a copy of the GNU General Public License 171573Srgrimes// along with this library; see the file COPYING. If not, write to 181573Srgrimes// the Free Software Foundation, 59 Temple Place - Suite 330, Boston, 191573Srgrimes// MA 02111-1307, USA. 201573Srgrimes 211573Srgrimes// As a special exception, you may use this file as part of a free 221573Srgrimes// software library without restriction. Specifically, if other files 231573Srgrimes// instantiate templates or use macros or inline functions from this 241573Srgrimes// file, or you compile this file and link it with other files to 251573Srgrimes// produce an executable, this file does not by itself cause the 261573Srgrimes// resulting executable to be covered by the GNU General Public 271573Srgrimes// License. This exception does not however invalidate any other 281573Srgrimes// reasons why the executable file might be covered by the GNU General 291573Srgrimes// Public License. 301573Srgrimes 311573Srgrimes// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. 321573Srgrimes 331573Srgrimes// Permission to use, copy, modify, sell, and distribute this software 341573Srgrimes// is hereby granted without fee, provided that the above copyright 351573Srgrimes// notice appears in all copies, and that both that copyright notice 361573Srgrimes// and this permission notice appear in supporting documentation. None 371573Srgrimes// of the above authors, nor IBM Haifa Research Laboratories, make any 381573Srgrimes// representation about the suitability of this software for any 391573Srgrimes// purpose. It is provided "as is" without express or implied 401573Srgrimes// warranty. 411573Srgrimes 421573Srgrimes/** 431573Srgrimes * @file find_fn_imps.hpp 441573Srgrimes * Contains an implementation class for splay_tree_. 451573Srgrimes */ 461573Srgrimes 471573SrgrimesPB_DS_CLASS_T_DEC 481573Srgrimesinline typename PB_DS_CLASS_C_DEC::point_iterator 491573SrgrimesPB_DS_CLASS_C_DEC:: 501573Srgrimesfind(const_key_reference r_key) 511573Srgrimes{ 521573Srgrimes node_pointer p_found = find_imp(r_key); 531573Srgrimes if (p_found != base_type::m_p_head) 541573Srgrimes splay(p_found); 551573Srgrimes return point_iterator(p_found); 561573Srgrimes} 571573Srgrimes 581573SrgrimesPB_DS_CLASS_T_DEC 591573Srgrimesinline typename PB_DS_CLASS_C_DEC::const_point_iterator 601573SrgrimesPB_DS_CLASS_C_DEC:: 611573Srgrimesfind(const_key_reference r_key) const 621573Srgrimes{ 631573Srgrimes const node_pointer p_found = find_imp(r_key); 641573Srgrimes if (p_found != base_type::m_p_head) 651573Srgrimes const_cast<PB_DS_CLASS_C_DEC* >(this)->splay(p_found); 661573Srgrimes return point_iterator(p_found); 671573Srgrimes} 681573Srgrimes 691573SrgrimesPB_DS_CLASS_T_DEC 701573Srgrimesinline typename PB_DS_CLASS_C_DEC::node_pointer 711573SrgrimesPB_DS_CLASS_C_DEC:: 721573Srgrimesfind_imp(const_key_reference r_key) 731573Srgrimes{ 741573Srgrimes _GLIBCXX_DEBUG_ONLY(base_type::structure_only_assert_valid();) 751573Srgrimes node_pointer p_nd = base_type::m_p_head->m_p_parent; 761573Srgrimes while (p_nd != NULL) 771573Srgrimes if (!Cmp_Fn::operator()(PB_DS_V2F(p_nd->m_value), r_key)) 781573Srgrimes { 791573Srgrimes if (!Cmp_Fn::operator()(r_key, PB_DS_V2F(p_nd->m_value))) 801573Srgrimes return p_nd; 811573Srgrimes p_nd = p_nd->m_p_left; 821573Srgrimes } 831573Srgrimes else 841573Srgrimes p_nd = p_nd->m_p_right; 851573Srgrimes return base_type::m_p_head; 861573Srgrimes} 871573Srgrimes 881573SrgrimesPB_DS_CLASS_T_DEC 891573Srgrimesinline const typename PB_DS_CLASS_C_DEC::node_pointer 901573SrgrimesPB_DS_CLASS_C_DEC:: 911573Srgrimesfind_imp(const_key_reference r_key) const 921573Srgrimes{ 931573Srgrimes _GLIBCXX_DEBUG_ONLY(assert_valid();) 941573Srgrimes node_pointer p_nd = base_type::m_p_head->m_p_parent; 951573Srgrimes while (p_nd != NULL) 961573Srgrimes if (!Cmp_Fn::operator()(PB_DS_V2F(p_nd->m_value), r_key)) 971573Srgrimes { 981573Srgrimes if (!Cmp_Fn::operator()(r_key, PB_DS_V2F(p_nd->m_value))) 991573Srgrimes return p_nd; 1001573Srgrimes p_nd = p_nd->m_p_left; 1011573Srgrimes } 1021573Srgrimes else 1031573Srgrimes p_nd = p_nd->m_p_right; 1041573Srgrimes return base_type::m_p_head; 1051573Srgrimes} 1061573Srgrimes