From 707cc94fe52463870a9c6c8e2e66eaaa389e601d Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Tue, 24 Feb 2009 15:16:26 +0200 Subject: Start tracking XSD/e with git after version 3.0.0 --- libxsde/xsde/cxx/hashmap.ixx | 177 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 177 insertions(+) create mode 100644 libxsde/xsde/cxx/hashmap.ixx (limited to 'libxsde/xsde/cxx/hashmap.ixx') diff --git a/libxsde/xsde/cxx/hashmap.ixx b/libxsde/xsde/cxx/hashmap.ixx new file mode 100644 index 0000000..a2d2a1b --- /dev/null +++ b/libxsde/xsde/cxx/hashmap.ixx @@ -0,0 +1,177 @@ +// file : xsde/cxx/hashmap.ixx +// author : Boris Kolpackov +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +namespace xsde +{ + namespace cxx + { + // const_iterator + // + inline hashmap_const_iterator hashmap_const_iterator:: + operator++ (int) + { + hashmap_const_iterator r (*this); + ++(*this); + return r; + } + + inline bool + operator== (const hashmap_const_iterator& i, + const hashmap_const_iterator& j) + { + return i.map_ == j.map_ && + i.bucket_ == j.bucket_ && + i.element_ == j.element_; + } + + inline bool + operator!= (const hashmap_const_iterator& i, + const hashmap_const_iterator& j) + { + return !(i == j); + } + + // hashmap + // + +#ifndef XSDE_EXCEPTIONS + inline hashmap::error hashmap:: + _error () const + { + return error_; + } +#endif + + inline bool hashmap:: + empty () const + { + return ecount_ == 0; + } + + inline size_t hashmap:: + size () const + { + return ecount_; + } + + inline const hashmap::bucket* hashmap:: + find (size_t h) const + { + return *(buckets_ + h % bcount_); + } + + inline hashmap::const_iterator hashmap:: + begin () const + { + return const_iterator (*this, ecount_ ? 0 : bcount_); + } + + inline hashmap::const_iterator hashmap:: + end () const + { + return const_iterator (*this, bcount_); + } + + // Fowler/Noll/Vo (FNV) hash (type FNV-1a) + // +#if XSDE_ARCH_WIDTH == 32 + inline size_t hashmap:: + hash (const char* s) + { + size_t r = static_cast (2166136261UL); + for (; *s != 0; ++s) + { + r ^= static_cast (*s); + r *= static_cast (16777619UL); + } + return r; + } + + inline size_t hashmap:: + hash (const char* s, size_t n) + { + size_t r = static_cast (2166136261UL); + for (; n > 0; --n) + { + r ^= static_cast (*s++); + r *= static_cast (16777619UL); + } + return r; + } + + inline size_t hashmap:: + hash (size_t h, const char* s) + { + for (; *s != 0; ++s) + { + h ^= static_cast (*s); + h *= static_cast (16777619UL); + } + return h; + } + + inline size_t hashmap:: + hash (size_t h, const char* s, size_t n) + { + for (; n > 0; --n) + { + h ^= static_cast (*s++); + h *= static_cast (16777619UL); + } + return h; + } + +#elif XSDE_ARCH_WIDTH == 64 + + inline size_t hashmap:: + hash (const char* s) + { + size_t r = static_cast (14695981039346656037ULL); + for (; *s != 0; ++s) + { + r ^= static_cast (*s); + r *= static_cast (1099511628211ULL); + } + return r; + } + + inline size_t hashmap:: + hash (const char* s, size_t n) + { + size_t r = static_cast (14695981039346656037ULL); + for (; n > 0; --n) + { + r ^= static_cast (*s++); + r *= static_cast (1099511628211ULL); + } + return r; + } + + inline size_t hashmap:: + hash (size_t h, const char* s) + { + for (; *s != 0; ++s) + { + h ^= static_cast (*s); + h *= static_cast (1099511628211ULL); + } + return h; + } + + inline size_t hashmap:: + hash (size_t h, const char* s, size_t n) + { + for (; n > 0; --n) + { + h ^= static_cast (*s++); + h *= static_cast (1099511628211ULL); + } + return h; + } +#else +#error there is no suitable hash function for this architecture width +#endif // XSDE_ARCH_WIDTH + } +} -- cgit v1.1