aboutsummaryrefslogtreecommitdiffstats
path: root/apps/files/src/utils/hashUtils.ts
diff options
context:
space:
mode:
Diffstat (limited to 'apps/files/src/utils/hashUtils.ts')
-rw-r--r--apps/files/src/utils/hashUtils.ts35
1 files changed, 12 insertions, 23 deletions
diff --git a/apps/files/src/utils/hashUtils.ts b/apps/files/src/utils/hashUtils.ts
index 55cf8b9f51a..2e1fadff067 100644
--- a/apps/files/src/utils/hashUtils.ts
+++ b/apps/files/src/utils/hashUtils.ts
@@ -1,28 +1,17 @@
/**
- * @copyright Copyright (c) 2023 John Molakvoæ <skjnldsv@protonmail.com>
- *
- * @author John Molakvoæ <skjnldsv@protonmail.com>
- *
- * @license AGPL-3.0-or-later
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
+ * SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
+/**
+ * Simple non-secure hashing function similar to Java's `hashCode`
+ * @param str The string to hash
+ * @return {number} a non secure hash of the string
+ */
export const hashCode = function(str: string): number {
- return str.split('').reduce(function(a, b) {
- a = ((a << 5) - a) + b.charCodeAt(0)
- return a & a
- }, 0)
+ let hash = 0
+ for (let i = 0; i < str.length; i++) {
+ hash = ((hash << 5) - hash + str.charCodeAt(i)) | 0
+ }
+ return (hash >>> 0)
}