174462Salfred// -*- C++ -*-
214123Speter
314123Speter// Copyright (C) 2005 Free Software Foundation, Inc.
414123Speter//
514123Speter// This file is part of the GNU ISO C++ Library.  This library is free
614123Speter// software; you can redistribute it and/or modify it under the
714123Speter// terms of the GNU General Public License as published by the
814123Speter// Free Software Foundation; either version 2, or (at your option)
914123Speter// any later version.
1014123Speter
1114123Speter// This library is distributed in the hope that it will be useful,
1214123Speter// but WITHOUT ANY WARRANTY; without even the implied warranty of
1314123Speter// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1414123Speter// GNU General Public License for more details.
1514123Speter
1614123Speter// You should have received a copy of the GNU General Public License along
1714123Speter// with this library; see the file COPYING.  If not, write to the Free
1814123Speter// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
1914123Speter// USA.
2014123Speter
2114123Speter// As a special exception, you may use this file as part of a free software
2214123Speter// library without restriction.  Specifically, if other files instantiate
2314123Speter// templates or use macros or inline functions from this file, or you compile
2414123Speter// this file and link it with other files to produce an executable, this
2514123Speter// file does not by itself cause the resulting executable to be covered by
2614123Speter// the GNU General Public License.  This exception does not however
2714123Speter// invalidate any other reasons why the executable file might be covered by
2814123Speter// the GNU General Public License.
2914123Speter
3014123Speter// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL.
3114123Speter
3214123Speter// Permission to use, copy, modify, sell, and distribute this software
3314123Speter// is hereby granted without fee, provided that the above copyright
34141580Sru// notice appears in all copies, and that both that copyright notice and
3514123Speter// this permission notice appear in supporting documentation. None of
36173281Smatteo// the above authors, nor IBM Haifa Research Laboratories, make any
3715096Smpp// representation about the suitability of this software for any
3814123Speter// purpose. It is provided "as is" without express or implied warranty.
3914123Speter
4015096Smpp/**
4114123Speter * @file hash_mod_example.cpp
4214123Speter * An example showing how to use a mod range-hasing function
4368965Sru */
4474462Salfred
4574462Salfred// For cc_hash_assoc_cntnr.
46173281Smatteo#include <ext/pb_assoc/assoc_cntnr.hpp>
47168324Smatteo// For direct_mask_range_hashing and hash_standard_resize_policy.
4814123Speter#include <ext/pb_assoc/hash_policy.hpp>
4974462Salfred// For unary_function, binary_function.
5074462Salfred#include <functional>
5199968Scharnier/*
5274462Salfred * A simple hash functor.
5374462Salfred *	std::hash could serve instead of this functor,
5474462Salfred *	but it is not yet standard everywhere.
5574462Salfred */
5674462Salfredstruct int_hash : public std::unary_function<
5714123Speter  int,
5874462Salfred	     size_t>
5974462Salfred{
6030376Scharnier  inline size_t
6114123Speter  operator()(int i) const
6274462Salfred  {
6374462Salfred    return (i);
6474462Salfred  }
6574462Salfred};
6674462Salfred
6774462Salfredint
6874462Salfredmain()
6974462Salfred{
7074462Salfred  /*
7174462Salfred   * A collision-chaining hash table mapping ints to chars.
7274462Salfred   */
7374462Salfred  typedef
7474462Salfred    pb_assoc::cc_hash_assoc_cntnr<
7514123Speter    int,
7614123Speter    char,
7774462Salfred    int_hash,
7874462Salfred    std::equal_to<int>,
7974462Salfred    // Combining function.
8074462Salfred    pb_assoc::direct_mod_range_hashing<> >
8174462Salfred    map_t;
8274462Salfred
8374462Salfred  map_t c;
8474462Salfred
8574462Salfred  c[32] = 'b';
8674462Salfred  c[1024] = 'c';
8774462Salfred  c[4096] = 'd';
88173281Smatteo}
89173281Smatteo
90173281Smatteo