Skip to content

Commit 9a0c984

Browse files
authored
Merge pull request #2029 from floccusaddon/feat/xxhash3
feat(hashing): Add support for xxhash3
2 parents 1772525 + 31eaa1c commit 9a0c984

File tree

10 files changed

+155
-122
lines changed

10 files changed

+155
-122
lines changed

package-lock.json

Lines changed: 138 additions & 115 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@
111111
"send-intent": "7.x",
112112
"stream-browserify": "^3.0.0",
113113
"throttle-debounce": "^2.3.0",
114+
"ts-xxhash": "^1.0.6",
114115
"vue": "^2.7.0",
115116
"vue-router": "^3.4.9",
116117
"vuelidate": "^0.7.6",

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 { XXHash32 } from 'ts-xxhash'
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 XXHash32.hash(0, message).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[cacheKey] = 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)