"Fossies" - the Fresh Open Source Software Archive

Member "aspell-0.60.8/common/hash_fun.hpp" (8 Oct 2019, 1936 Bytes) of package /linux/misc/aspell-0.60.8.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "hash_fun.hpp" see the Fossies "Dox" file reference documentation.

    1 // Copyright (c) 2001
    2 // Kevin Atkinson
    3 //
    4 // Permission to use, copy, modify, distribute and sell this software
    5 // and its documentation for any purpose is hereby granted without
    6 // fee, provided that the above copyright notice appear in all copies
    7 // and that both that copyright notice and this permission notice
    8 // appear in supporting documentation. Kevin Atkinson makes no
    9 // representations about the suitability of this software for any
   10 // purpose.  It is provided "as is" without express or implied
   11 // warranty.
   12 
   13 #ifndef acommon_hash_fun__hpp
   14 #define acommon_hash_fun__hpp
   15 
   16 namespace acommon {
   17   
   18   template <typename K> struct hash {};
   19 
   20   template <> struct hash<char>  {unsigned long operator()(char  v) const {return v;}};
   21   template <> struct hash<short> {unsigned long operator()(short v) const {return v;}};
   22   template <> struct hash<int>   {unsigned long operator()(int   v) const {return v;}};
   23   template <> struct hash<long>  {unsigned long operator()(long  v) const {return v;}};
   24   template <> struct hash<unsigned char>  {unsigned long operator()(unsigned char  v) const {return v;}};
   25   template <> struct hash<unsigned short> {unsigned long operator()(unsigned short v) const {return v;}};
   26   template <> struct hash<unsigned int>   {unsigned long operator()(unsigned int   v) const {return v;}};
   27   template <> struct hash<unsigned long>  {unsigned long operator()(unsigned long  v) const {return v;}};
   28 
   29   template <> struct hash<const char *> {
   30     inline unsigned long operator() (const char * s) const {
   31       unsigned long h = 0;
   32       for (; *s; ++s)
   33     h=5*h + *s;
   34       return h;
   35     }
   36   };
   37 
   38   template<class Str>
   39   struct HashString {
   40     inline unsigned long operator() (const Str &str) const {
   41       unsigned long h = 0;
   42       typename Str::const_iterator end = str.end();
   43       for (typename Str::const_iterator s = str.begin(); 
   44        s != end; 
   45        ++s)
   46     h=5*h + *s;
   47       return h;
   48     }
   49   };
   50   
   51 }
   52 
   53 #endif