Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(19)

Side by Side Diff: native_client_sdk/src/libraries/nacl_io/hash.cc

Issue 2156503002: [NaCl SDK] Expose Google Drive to nacl_io. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "nacl_io/hash.h"
6 #include "nacl_io/osdirent.h"
7
8 namespace nacl_io {
9
10 ino_t HashPathSegment(ino_t hash, const char* str, size_t len) {
11 // First add the path seperator
12 hash = (hash * static_cast<ino_t>(33)) ^ '/';
13 while (len--) {
14 hash = (hash * static_cast<ino_t>(33)) ^ *str++;
15 }
16 return hash;
17 }
18
19 ino_t HashPath(const Path& path) {
20 // Prime the DJB2a hash
21 ino_t hash = 5381;
22
23 // Apply a running DJB2a to each part of the path
24 for (size_t segment = 0; segment < path.Size(); segment++) {
25 const std::string& part = path.Part(segment);
26 hash = HashPathSegment(hash, part.c_str(), part.length());
27 }
28 return hash;
29 }
30
31 } // namespace nacl_io
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698