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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: native_client_sdk/src/libraries/nacl_io/hash.cc
diff --git a/native_client_sdk/src/libraries/nacl_io/hash.cc b/native_client_sdk/src/libraries/nacl_io/hash.cc
new file mode 100644
index 0000000000000000000000000000000000000000..6293fae4a2538220006dea7ce9af0f87fa6b0c36
--- /dev/null
+++ b/native_client_sdk/src/libraries/nacl_io/hash.cc
@@ -0,0 +1,31 @@
+// Copyright (c) 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "nacl_io/hash.h"
+#include "nacl_io/osdirent.h"
+
+namespace nacl_io {
+
+ino_t HashPathSegment(ino_t hash, const char* str, size_t len) {
+ // First add the path seperator
+ hash = (hash * static_cast<ino_t>(33)) ^ '/';
+ while (len--) {
+ hash = (hash * static_cast<ino_t>(33)) ^ *str++;
+ }
+ return hash;
+}
+
+ino_t HashPath(const Path& path) {
+ // Prime the DJB2a hash
+ ino_t hash = 5381;
+
+ // Apply a running DJB2a to each part of the path
+ for (size_t segment = 0; segment < path.Size(); segment++) {
+ const std::string& part = path.Part(segment);
+ hash = HashPathSegment(hash, part.c_str(), part.length());
+ }
+ return hash;
+}
+
+} // namespace nacl_io

Powered by Google App Engine
This is Rietveld 408576698