~ubuntu-branches/ubuntu/wily/opencollada/wily-proposed

« back to all changes in this revision

Viewing changes to COLLADABaseUtils/src/COLLADABUHashFunctions.cpp

  • Committer: Package Import Robot
  • Author(s): Matteo F. Vescovi
  • Date: 2015-05-14 17:23:27 UTC
  • Revision ID: package-import@ubuntu.com-20150514172327-f862u8envms01fra
Tags: upstream-0.1.0~20140703.ddf8f47+dfsg1
ImportĀ upstreamĀ versionĀ 0.1.0~20140703.ddf8f47+dfsg1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
    Copyright (c) 2008-2009 NetAllied Systems GmbH
 
3
 
 
4
    This file is part of COLLADABaseUtils.
 
5
 
 
6
    Licensed under the MIT Open Source License,
 
7
    for details please see LICENSE file or the website
 
8
    http://www.opensource.org/licenses/mit-license.php
 
9
*/
 
10
 
 
11
#include "COLLADABUStableHeaders.h"
 
12
#include "COLLADABUHashFunctions.h"
 
13
#include "COLLADABUURI.h"
 
14
#include "COLLADABUStringUtils.h"
 
15
 
 
16
namespace COLLADABU
 
17
{
 
18
        size_t calculateHash( const String& str )
 
19
        {
 
20
                return calculateHash(str.c_str());
 
21
        }
 
22
 
 
23
        size_t calculateHashUpper( const String& str )
 
24
        {
 
25
                return calculateHashUpper(str.c_str());
 
26
        }
 
27
 
 
28
        size_t calculateHash( const char* str )
 
29
        {
 
30
                unsigned long h = 0;
 
31
                unsigned long g;
 
32
                const char* pos = str;
 
33
 
 
34
                while (*pos != 0) {
 
35
                        h = (h << 4) + *pos++;
 
36
                        if ((g = (h & 0xf0000000)) != 0)
 
37
                                h ^= g >> 24;
 
38
                        h &= ~g;
 
39
                }
 
40
                return h;
 
41
        }
 
42
 
 
43
        size_t calculateHashUpper( const char* str )
 
44
        {
 
45
                unsigned long h = 0;
 
46
                unsigned long g;
 
47
                const char* pos = str;
 
48
 
 
49
                while (*pos != 0) {
 
50
                        h = (h << 4) + StringUtils::toUpperASCIIChar(*pos++);
 
51
                        if ((g = (h & 0xf0000000)) != 0)
 
52
                                h ^= g >> 24;
 
53
                        h &= ~g;
 
54
                }
 
55
                return h;
 
56
        }
 
57
 
 
58
        size_t calculateHash( const URI& uri )
 
59
        {
 
60
                return calculateHash(uri.getURIString());
 
61
        }
 
62
 
 
63
 
 
64
 
 
65
} // namespace COLLADABU