X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Ftag.cpp;h=76adf7d1b53ccd5e681686335132ff6b265f64b7;hb=56c9bfa0b47583fb9067705a69c3639a17d4a097;hp=c8041e0d0331c8c20fc7f78a657b39d651e5daab;hpb=c6aea1bc1586ffef132e6fffdf99343cb56617db;p=libs%2Fgl.git diff --git a/source/tag.cpp b/source/tag.cpp index c8041e0d..76adf7d1 100644 --- a/source/tag.cpp +++ b/source/tag.cpp @@ -1,21 +1,35 @@ +/* $Id$ + +This file is part of libmspgl +Copyright © 2007, 2010 Mikko Rasa, Mikkosoft Productions +Distributed under the LGPL +*/ + #include "tag.h" +namespace { + +template +inline unsigned hash(T begin, T end) +{ + unsigned result=0; + for(T i=begin; (i!=end && *i); ++i) + result=((result>>29)|(result<<5))^static_cast(*i); + return result; +} + +} + namespace Msp { namespace GL { Tag::Tag(const char *s): - id(0) -{ - for(const char *i=s; *i; ++i) - id=id*id+*i; -} + id(s ? hash(s, 0) : 0) +{ } Tag::Tag(const std::string &s): - id(0) -{ - for(std::string::const_iterator i=s.begin(); i!=s.end(); ++i) - id=id*id+*i; -} + id(hash(s.begin(), s.end())) +{ } } // namespace GL } // namespace Msp