Skip to content

Commit

Permalink
Add comments to autocomplete.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
TyHil committed Oct 19, 2023
1 parent 0a402bf commit 5e5462d
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions pages/api/autocomplete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ class PriorityQueue {
}
}

// bfs search from node in DAG, only until next result can be returned
function bfsRecursionToNextData(queue: PriorityQueue) {
const queueItem = queue.dequeue();
if (graph.getNodeAttribute(queueItem?.data?.node, 'visited')) {
Expand Down Expand Up @@ -107,6 +108,7 @@ function bfsRecursionToNextData(queue: PriorityQueue) {
return;
}

// bfs search from node in DAG, adding children to priorirty queue if parant matches search string
function bfsRecursion(queue: PriorityQueue) {
const queueItem = queue.dequeue();
if (typeof queueItem?.data === 'undefined') {
Expand Down Expand Up @@ -193,6 +195,7 @@ function bfsRecursion(queue: PriorityQueue) {

type bfsReturn = SearchQuery | undefined;

// search autocomplete program using a DAG (more specifically a radix tree) to search for matches until limit is reached
function searchAutocomplete(query: string, limit: number) {
query = query.trimStart().toUpperCase();
graph.updateEachNodeAttributes((node, attr) => {
Expand Down

0 comments on commit 5e5462d

Please sign in to comment.