X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Ftag.cpp;h=af92bbb8b60780cb0827a63e8d0ea3c6795299d6;hb=b07e3b2103c53e3cd6a4674eef481178ec64f2c7;hp=8e29bee1f3eba6f97665bc9abd0e3fb60dd24d99;hpb=19583522999f9ca2cddb178691633bc20f714b01;p=libs%2Fgl.git diff --git a/source/tag.cpp b/source/tag.cpp index 8e29bee1..af92bbb8 100644 --- a/source/tag.cpp +++ b/source/tag.cpp @@ -1,28 +1,28 @@ -/* $Id$ +#include "tag.h" -This file is part of libmspgl -Copyright © 2007 Mikko Rasa, Mikkosoft Productions -Distributed under the LGPL -*/ +namespace { -#include "tag.h" +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