Skip to content

Commit 9f73d7a

Browse files
committed
feat(hashing): Add support for xxhash3
Signed-off-by: Marcel Klehr <mklehr@gmx.net>
1 parent 732a7a5 commit 9f73d7a

10 files changed

Lines changed: 35 additions & 9 deletions

File tree

package-lock.json

Lines changed: 17 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,8 @@
116116
"vuelidate": "^0.7.6",
117117
"vuetify": "^2.6.15",
118118
"vuex": "^3.6.0",
119-
"vuex-router-sync": "^5.0.0"
119+
"vuex-router-sync": "^5.0.0",
120+
"xxhashjs": "^0.2.2"
120121
},
121122
"browserslist": [
122123
"> 0.25%",

src/lib/Crypto.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
import { fromUint8Array, toUint8Array } from 'js-base64'
22
import { murmurhash3_32_gc } from './murmurhash3'
3+
import xxh from 'xxhashjs'
34

45
export default class Crypto {
56
static iterations = 250000
67
static ivLength = 16
78

9+
static async xxhash32(message: string): Promise<string> {
10+
return xxh.h32(message, 0).toString(16)
11+
}
12+
813
static async murmurHash3(message: string): Promise<string> {
914
const buf32 = new Uint32Array([murmurhash3_32_gc(message, 0)])
1015
const buf8 = new Uint8Array(buf32.buffer)

src/lib/LocalTabs.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,7 @@ export default class LocalTabs implements OrderFolderResource<typeof ItemLocatio
506506
async getCapabilities(): Promise<ICapabilities> {
507507
return {
508508
preserveOrder: true,
509-
hashFn: ['murmur3', 'sha256']
509+
hashFn: ['xxhash3', 'murmur3', 'sha256']
510510
}
511511
}
512512

src/lib/Tree.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,14 @@ export class Bookmark<L extends TItemLocation> {
8484
this.hashValue[cacheKey] = value
8585
}
8686

87-
async hash({preserveOrder = false, hashFn = 'sha256'}):Promise<string> {
87+
async hash({preserveOrder = false, hashFn = 'sha256'}: IHashSettings = {preserveOrder: false, hashFn: 'sha256'}):Promise<string> {
8888
if (!this.hashValue) {
8989
this.hashValue = {}
9090
const json = JSON.stringify({ title: this.title, url: this.url })
9191
if (hashFn === 'sha256') {
9292
this.hashValue[hashFn] = await Crypto.sha256(json)
93+
} else if (hashFn === 'xxhash3') {
94+
this.hashValue[hashFn] = await Crypto.xxhash32(json)
9395
} else if (hashFn === 'murmur3') {
9496
this.hashValue[hashFn] = await Crypto.murmurHash3(json)
9597
} else {
@@ -361,6 +363,8 @@ export class Folder<L extends TItemLocation> {
361363
this.hashValue[cacheKey] = await Crypto.sha256(json)
362364
} else if (hashFn === 'murmur3') {
363365
this.hashValue[cacheKey] = await Crypto.murmurHash3(json)
366+
} else if (hashFn === 'xxhash3') {
367+
this.hashValue[hashFn] = await Crypto.xxhash32(json)
364368
} else {
365369
throw new Error('Unsupported hash function specified')
366370
}

src/lib/adapters/Caching.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ export default class CachingAdapter implements Adapter, BulkImportResource<TItem
250250
async getCapabilities(): Promise<ICapabilities> {
251251
return {
252252
preserveOrder: true,
253-
hashFn: ['murmur3', 'sha256'],
253+
hashFn: ['xxhash3', 'murmur3', 'sha256'],
254254
}
255255
}
256256

src/lib/adapters/Karakeep.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -569,7 +569,7 @@ export default class KarakeepAdapter implements Adapter, IResource<typeof ItemLo
569569
async getCapabilities(): Promise<ICapabilities> {
570570
return {
571571
preserveOrder: false,
572-
hashFn: ['murmur3', 'sha256'],
572+
hashFn: ['xxhash3', 'murmur3', 'sha256'],
573573
}
574574
}
575575

src/lib/adapters/Linkwarden.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ export default class LinkwardenAdapter implements Adapter, IResource<typeof Item
371371
async getCapabilities(): Promise<ICapabilities> {
372372
return {
373373
preserveOrder: false,
374-
hashFn: ['murmur3', 'sha256'],
374+
hashFn: ['xxhash3', 'murmur3', 'sha256'],
375375
}
376376
}
377377

src/lib/browser/BrowserTree.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ export default class BrowserTree implements IResource<typeof ItemLocation.LOCAL>
397397
async getCapabilities(): Promise<ICapabilities> {
398398
return {
399399
preserveOrder: true,
400-
hashFn: ['murmur3', 'sha256']
400+
hashFn: ['xxhash3', 'murmur3', 'sha256']
401401
}
402402
}
403403

src/lib/interfaces/Resource.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Bookmark, Folder, ItemLocation, TItem, TItemLocation } from '../Tree'
22
import Ordering from './Ordering'
33

4-
export type THashFunction = 'sha256' | 'murmur3'
4+
export type THashFunction = 'sha256' | 'murmur3' | 'xxhash3'
55

66
export interface ICapabilities {
77
preserveOrder: boolean,

0 commit comments

Comments
 (0)