⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mstl_hash_function.hpp

📁 一个类STL的多平台可移植的算法容器库,主要用于嵌入式系统编程时的内存管理等方面
💻 HPP
字号:
/*
The young Library
Copyright (c) 2005 by 杨桓

Permission to use, copy, modify, distribute and sell this software for any
purpose is hereby granted without fee, provided that the above copyright
notice appear in all copies and that both that copyright notice and this
permission notice appear in supporting documentation.
The author make no representations about the suitability of this software
for any purpose. It is provided "as is" without express or implied warranty.
*/

/*
 * This file is derived from software bearing the following
 * restrictions:
 *
 * Copyright (c) 1994
 * Hewlett-Packard Company
 *
 * Permission to use, copy, modify, distribute and sell this
 * software and its documentation for any purpose is hereby
 * granted without fee, provided that the above copyright notice
 * appear in all copies and that both that copyright notice and
 * this permission notice appear in supporting documentation.
 * Hewlett-Packard Company makes no representations about the
 * suitability of this software for any purpose. It is provided
 * "as is" without express or implied warranty.
 */

//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
#ifndef __MACRO_CPLUSPLUS_MINI_STL_HASH_FUNCTION_HEADER_FILE__
#define __MACRO_CPLUSPLUS_MINI_STL_HASH_FUNCTION_HEADER_FILE__
//-----------------------------------------------------------------------------
#include "../mstl_define.hpp"
//-----------------------------------------------------------------------------
__MACRO_CPLUSPLUS_MINI_STL_BEGIN_NAMESPACE__
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------

template< typename Key >
struct hash {};

inline def_size_t hash_string( const char* s )
{
    unsigned long h = 0; 
    for ( ; *s; ++s )
        h = 5 * h + *s;
    return def_size_t(h);
}

template<>
struct hash<char*>
{
    def_size_t operator()( const char* s ) const
    {  return hash_string(s);  }
};

template<>
struct hash<const char*>
{
    def_size_t operator()( const char* s ) const
    {  return hash_string(s);  }
};

template<>
struct hash<char>
{
    def_size_t operator()( char x ) const
    {  return x;  }
};

template<>
struct hash<unsigned char>
{
    def_size_t operator()( unsigned char x ) const
    {  return x;  }
};

template<>
struct hash<signed char>
{
    def_size_t operator()( unsigned char x ) const
    {  return x;  }
};

template<>
struct hash<short>
{
    def_size_t operator()(short x) const
    {  return x;  }
};

template<>
struct hash<unsigned short>
{
    def_size_t operator()( unsigned short x ) const
    {  return x;  }
};

template<>
struct hash<int>
{
    def_size_t operator()( int x ) const
    {  return x;  }
};

template<>
struct hash<unsigned int>
{
    def_size_t operator()( unsigned int x ) const
    {  return x;  }
};

template<>
struct hash<long>
{
    def_size_t operator()( long x ) const
    {  return x;  }
};

template<>
struct hash<unsigned long>
{
    def_size_t operator()( unsigned long x ) const
    {  return x;  }
};

template<>
struct hash<long long>
{
    def_size_t operator()( long long x ) const
    {  return x;  }
};

template<>
struct hash<unsigned long long>
{
    def_size_t operator()( unsigned long long x ) const
    {  return x;  }
};

//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
__MACRO_CPLUSPLUS_MINI_STL_END_NAMESPACE__
#endif
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -