-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(PR-suggestions): made suggested PR changes by
Adding context to where the hashing function was found Renaming the data src to queryCache Renaming the imported function in TimeSeries Renaming some of the input parameters to be a little more relevant
- Loading branch information
Showing
8 changed files
with
63 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
export type Action = | ||
| ReturnType<typeof resetCachedQueryResults> | ||
| ReturnType<typeof setQueryResultsByQueryID> | ||
|
||
// Hashing function found here: | ||
// https://jsperf.com/hashcodelordvlad | ||
// Through this thread: | ||
// https://stackoverflow.com/questions/7616461/generate-a-hash-from-string-in-javascript | ||
export const hashCode = (queryText: string): string => { | ||
let hash = 0, | ||
char | ||
if (!queryText) { | ||
return `${hash}` | ||
} | ||
for (let i = 0; i < queryText.length; i++) { | ||
char = queryText.charCodeAt(i) | ||
hash = (hash << 5) - hash + char | ||
hash |= 0 // Convert to 32bit integer | ||
} | ||
return `${hash}` | ||
} | ||
|
||
export const setQueryResultsByQueryID = (queryID: string, files: string[]) => | ||
({ | ||
type: 'SET_QUERY_RESULTS_BY_QUERY', | ||
queryID: hashCode(queryID), | ||
files, | ||
} as const) | ||
|
||
export const resetCachedQueryResults = () => | ||
({ | ||
type: 'RESET_CACHED_QUERY_RESULTS', | ||
} as const) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters