Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: lib/typedObjects/hash.js

Issue 6253377650425856: WIP - Dictionary types implementation (Closed)
Patch Set: Created Jan. 9, 2015, 3:34 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « lib/typedObjects/dictionaryTypes.js ('k') | lib/typedObjects/objectTypes.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * This file is part of Adblock Plus <http://adblockplus.org/>,
3 * Copyright (C) 2006-2014 Eyeo GmbH
4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation.
8 *
9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18 "use strict";
19
20 /*
21 * Note: This implements the hash function by Paul Hsieh, see
22 * http://www.azillionmonkeys.com/qed/hash.html. The code below is based on Paul
23 * Hsieh's code which is licensed under LGPL 2.1.
24 */
25
26 exports.calculateHash = function calculateHash(/**string*/ str)
27 {
28 let length = str.length | 0;
29 let hash = length << 1;
30
31 for (let i = 0; i < length - 1; i += 2)
32 {
33 // Main loop, process two characters at a time
34 hash += str.get(i);
35 let tmp = (str.get(i + 1) << 11) ^ hash;
36 hash = (hash << 16) ^ tmp;
37 hash += hash >>> 11;
38 }
39
40 if (length & 1)
41 {
42 // Process remaining character
43 hash += str.get(length - 1);
44 hash ^= hash << 11;
45 hash += hash >>> 17;
46 }
47
48 // "Avalanching" of final 127 bits
49 hash ^= hash << 3;
50 hash += hash >>> 5;
51 hash ^= hash << 4;
52 hash += hash >>> 17;
53 hash ^= hash << 25;
54 hash += hash >>> 6;
55 return hash >>> 0;
56 }
OLDNEW
« no previous file with comments | « lib/typedObjects/dictionaryTypes.js ('k') | lib/typedObjects/objectTypes.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld