Skip to content

Commit

Permalink
perf: remove unused properties from radix (#435)
Browse files Browse the repository at this point in the history
  • Loading branch information
H4ad authored Jul 11, 2023
1 parent 6b3d9d4 commit 5fcc4bd
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 107 deletions.
10 changes: 2 additions & 8 deletions packages/orama/src/trees/radix.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import { syncBoundedLevenshtein } from '../components/levenshtein.js'
import { Nullable } from '../types.js'
import { getOwnProperty, syncUniqueId } from '../utils.js'
import { syncBoundedLevenshtein } from "../components/levenshtein.js";
import { getOwnProperty } from "../utils.js";

export interface Node {
id: string
key: string
subWord: string
parent: Nullable<string>
children: Record<string, Node>
docs: string[]
end: boolean
Expand All @@ -29,7 +26,6 @@ function serialize(this: Node): object {
}

function updateParent(node: Node, parent: Node): void {
node.parent = parent.id
node.word = parent.word + node.subWord
}

Expand Down Expand Up @@ -111,10 +107,8 @@ function getCommonPrefix(a: string, b: string) {

export function create(end = false, subWord = '', key = ''): Node {
const node = {
id: syncUniqueId(),
key,
subWord,
parent: null,
children: {},
docs: [],
end,
Expand Down
5 changes: 0 additions & 5 deletions packages/orama/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,6 @@ export async function uniqueId(): Promise<string> {
return `${baseId}-${lastId++}`
}

// This is only used internally, keep in sync with the previous one
export function syncUniqueId(): string {
return `${baseId}-${lastId++}`
}

export function getOwnProperty<T = unknown>(object: Record<string, T>, property: string): T | undefined {
// Checks if `hasOwn` method is defined avoiding errors with older Node.js versions
if (Object.hasOwn === undefined) {
Expand Down
Loading

1 comment on commit 5fcc4bd

@vercel
Copy link

@vercel vercel bot commented on 5fcc4bd Jul 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.