Skip to content

Commit

Permalink
feat(types): Add SearchResult type
Browse files Browse the repository at this point in the history
This commit adds the SearchResults type which contains the type of
search results found when searching for a string in a Trie
  • Loading branch information
theodesp committed Dec 4, 2023
1 parent e74ec27 commit 3e68cbe
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 66 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ for (let i = 0; i < searches.length; i += 1) {
// There was a match. Print match info
if (result) {
switch (result.matchType) {
case PERFECT_MATCH:
case PURE_PREFIX:
case PREFIX:
case "PERFECT_MATCH":
case "PURE_PREFIX":
case "PREFIX":
console.log(`${searches[i]}: Present in trie`);
}
}
Expand Down
44 changes: 0 additions & 44 deletions src/greet.test.ts

This file was deleted.

13 changes: 0 additions & 13 deletions src/greet.ts

This file was deleted.

1 change: 0 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
export * from "./greet.js";
export * from "./types.js";
33 changes: 28 additions & 5 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,28 @@
export interface GreetOptions {
logger?: (message: string) => void;
message: string;
times?: number;
}
/**
* Represents a search for a string that
* successfully ends at a leaf node.
*/
export type PERFECT_MATCH = {
matchType: "PERFECT_MATCH";
};

/**
* Represents a search for a string that
* successfully ends at a non-leaf node.
*/
export type PURE_PREFIX = {
matchType: "PURE_PREFIX";
};
/**
* Represents a search for a string that
* is successful. Not strictly necessary
* but useful as the disjunction of
* PERFECT_MATCH and PURE_PREFIX.
*/
export type PREFIX = {
matchType: "PREFIX";
};
/**
* Union type of all possible values of Trie SearchResult
*/
export type SearchResult = PERFECT_MATCH | PURE_PREFIX | PREFIX | undefined;

0 comments on commit 3e68cbe

Please sign in to comment.