libstdc++
sample_resize_trigger.hpp
Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010
00004 // Free Software Foundation, Inc.
00005 //
00006 // This file is part of the GNU ISO C++ Library.  This library is free
00007 // software; you can redistribute it and/or modify it under the terms
00008 // of the GNU General Public License as published by the Free Software
00009 // Foundation; either version 3, or (at your option) any later
00010 // version.
00011 
00012 // This library is distributed in the hope that it will be useful, but
00013 // WITHOUT ANY WARRANTY; without even the implied warranty of
00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015 // General Public License for more details.
00016 
00017 // Under Section 7 of GPL version 3, you are granted additional
00018 // permissions described in the GCC Runtime Library Exception, version
00019 // 3.1, as published by the Free Software Foundation.
00020 
00021 // You should have received a copy of the GNU General Public License and
00022 // a copy of the GCC Runtime Library Exception along with this program;
00023 // see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
00024 // <http://www.gnu.org/licenses/>.
00025 
00026 // Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL.
00027 
00028 // Permission to use, copy, modify, sell, and distribute this software
00029 // is hereby granted without fee, provided that the above copyright
00030 // notice appears in all copies, and that both that copyright notice
00031 // and this permission notice appear in supporting documentation. None
00032 // of the above authors, nor IBM Haifa Research Laboratories, make any
00033 // representation about the suitability of this software for any
00034 // purpose. It is provided "as is" without express or implied
00035 // warranty.
00036 
00037 /**
00038  * @file sample_resize_trigger.hpp
00039  * Contains a sample resize trigger policy class.
00040  */
00041 
00042 #ifndef PB_DS_SAMPLE_RESIZE_TRIGGER_HPP
00043 #define PB_DS_SAMPLE_RESIZE_TRIGGER_HPP
00044 
00045 namespace __gnu_pbds
00046 {
00047   /// A sample resize trigger policy.
00048   class sample_resize_trigger
00049   {
00050   public:
00051     /// Size type.
00052     typedef std::size_t size_type;
00053 
00054     /// Default constructor.
00055     sample_resize_trigger();
00056 
00057     /// Copy constructor.
00058     sample_range_hashing(const sample_resize_trigger&);
00059 
00060     /// Swaps content.
00061     inline void
00062     swap(sample_resize_trigger&);
00063 
00064   protected:
00065     /// Notifies a search started.
00066     inline void
00067     notify_insert_search_start();
00068 
00069     /// Notifies a search encountered a collision.
00070     inline void
00071     notify_insert_search_collision();
00072 
00073     /// Notifies a search ended.
00074     inline void
00075     notify_insert_search_end();
00076 
00077     /// Notifies a search started.
00078     inline void
00079     notify_find_search_start();
00080 
00081     /// Notifies a search encountered a collision.
00082     inline void
00083     notify_find_search_collision();
00084 
00085     /// Notifies a search ended.
00086     inline void
00087     notify_find_search_end();
00088 
00089     /// Notifies a search started.
00090     inline void
00091     notify_erase_search_start();
00092 
00093     /// Notifies a search encountered a collision.
00094     inline void
00095     notify_erase_search_collision();
00096 
00097     /// Notifies a search ended.
00098     inline void
00099     notify_erase_search_end();
00100 
00101     /// Notifies an element was inserted. the total number of entries in
00102     /// the table is num_entries.
00103     inline void
00104     notify_inserted(size_type num_entries);
00105 
00106     /// Notifies an element was erased.
00107     inline void
00108     notify_erased(size_type num_entries);
00109 
00110     /// Notifies the table was cleared.
00111     void
00112     notify_cleared();
00113 
00114     /// Notifies the table was resized as a result of this object's
00115     /// signifying that a resize is needed.
00116     void
00117     notify_resized(size_type new_size);
00118 
00119     /// Notifies the table was resized externally.
00120     void
00121     notify_externally_resized(size_type new_size);
00122 
00123     /// Queries whether a resize is needed.
00124     inline bool
00125     is_resize_needed() const;
00126 
00127     /// Queries whether a grow is needed.
00128     inline bool
00129     is_grow_needed(size_type size, size_type num_entries) const;
00130 
00131   private:
00132     /// Resizes to new_size.
00133     virtual void
00134     do_resize(size_type);
00135   };
00136 }
00137 #endif