Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding chowdsp_fuzzy_search #497

Merged
merged 7 commits into from
Feb 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
tests: [
"chowdsp_core_test chowdsp_data_structures_test chowdsp_json_test chowdsp_serialization_test chowdsp_logging_test chowdsp_units_test chowdsp_buffers_test chowdsp_dsp_juce_test", # common_tests_lib + dsp_juce_tests_lib
"chowdsp_dsp_data_structures_test chowdsp_dsp_utils_test chowdsp_filters_test chowdsp_math_test chowdsp_modal_dsp_test chowdsp_simd_test chowdsp_sources_test chowdsp_waveshapers_test chowdsp_compressor_test", # dsp_tests_lib
"chowdsp_parameters_test chowdsp_plugin_state_test chowdsp_plugin_base_test chowdsp_plugin_utils_test chowdsp_presets_v2_test chowdsp_version_test", # plugin_tests_lib
"chowdsp_parameters_test chowdsp_plugin_state_test chowdsp_plugin_base_test chowdsp_plugin_utils_test chowdsp_presets_v2_test chowdsp_version_test chowdsp_fuzzy_search_test", # plugin_tests_lib
"chowdsp_gui_test chowdsp_visualizers_test", # gui_tests_lib
]
name: [
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

All notable changes to this project will be documented in this file.

## [UNRELEASED]
- Added `chowdsp_fuzzy_search` module.

## [2.2.0] 2024-02-19
- Refactored `chowdsp_buffers` module out of `chowdsp_dsp_data_structures`.
- Refactored `chowdsp_data_structures` module out of `chowdsp_core`, and added new data structures.
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,6 @@ sure to abide by the license of each module, as well as whichever libraries are

`chowdsp_plugin_utils` (GPLv3)
- `FileListener`: A listener which triggers a callback whenever a file is changed.
- `PluginLogger`: A logging system which can be used within a plugin.
- `SharedPluginSettings`: A shared object for managing settings which apply to all instances of a plugin.
- `SharedLNFAllocator`: A shared object for managing `juce::LookAndFeel` classes.
- `AudioUIBackgroundThread`: A thread class which accepts data from the audio thread, and performs a background task (often useful for creating meters).
Expand All @@ -252,6 +251,9 @@ sure to abide by the license of each module, as well as whichever libraries are
`chowdsp_version` (BSD)
- Utilities for managing the version of an app or plugin.

`chowdsp_fuzzy_search` (BSD)
- A tag-based fuzzy searching system, based on [fuzzysearchdatabase](https://bitbucket.org/j_norberg/fuzzysearchdatabase).

## Development

The development environment for this repository expects the following
Expand Down
1 change: 1 addition & 0 deletions cmake/AddJUCEModules.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ juce_add_modules(
${PROJECT_SOURCE_DIR}/modules/plugin/chowdsp_plugin_utils
${PROJECT_SOURCE_DIR}/modules/plugin/chowdsp_clap_extensions
${PROJECT_SOURCE_DIR}/modules/plugin/chowdsp_plugin_state
${PROJECT_SOURCE_DIR}/modules/plugin/chowdsp_fuzzy_search

${PROJECT_SOURCE_DIR}/modules/gui/chowdsp_gui
${PROJECT_SOURCE_DIR}/modules/gui/chowdsp_foleys
Expand Down
1 change: 1 addition & 0 deletions cmake/test/SetupCodeQuality.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ target_link_libraries(chowdsp_utils_codeql PRIVATE
chowdsp::chowdsp_reflection
chowdsp::chowdsp_serialization
chowdsp::chowdsp_logging
chowdsp::chowdsp_fuzzy_search
chowdsp::chowdsp_units
chowdsp::chowdsp_buffers
chowdsp::chowdsp_compressor
Expand Down
1 change: 1 addition & 0 deletions cmake/test/SetupStaticTests.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ target_link_libraries(static_test_dummy_executable PRIVATE
chowdsp_reflection
chowdsp_serialization
chowdsp_logging
chowdsp_fuzzy_search
chowdsp_units
chowdsp_buffers
chowdsp_compressor
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#pragma once

namespace chowdsp::search_database
{
/** Storage for a set of words in "flat" memory */
struct WordStorage
{
/** A "view" into a word in the flat buffer */
struct WordView
{
uint32_t start = 0;
uint32_t end = 0;
};

std::vector<char> wordData {}; // all characters from a word, in order in memory
std::vector<search_helpers::WordHist> wordHist {}; // a tiny histogram per word
std::vector<WordView> wordViewList {}; // map to find index from word
std::unordered_map<std::string, size_t> wordMap {};

/**
* Gets a std::string_view from a WordView.
* This method does not perform any additional validation.
*/
[[nodiscard]] std::string_view getString (WordView wordView) const noexcept
{
return { wordData.data() + wordView.start, wordView.end - wordView.start };
}

/** Clears the storage. */
void clear()
{
wordData.clear();
wordHist.clear();
wordViewList.clear();
wordMap.clear();
}

/** Reserves memory for a given number of words. */
void reserve (size_t wordCount)
{
wordData.reserve (wordCount * 8); // assuming ~8 characters per word
wordHist.reserve (wordCount);
wordViewList.reserve (wordCount);
wordMap.reserve (wordCount);
}

/** Returns the number of words currently in storage. */
[[nodiscard]] auto getWordCount() const noexcept { return wordViewList.size(); }

/**
* Adds a word to the storage, and returns the "index"
* at which the word can be found in the `wordViewList`.
*/
[[nodiscard]] int addWord (std::string_view word)
{
// if exist, return index
if (auto found = wordMap.find (std::string { word }); found != wordMap.end())
return static_cast<int> (found->second);

const auto newWordIndex = static_cast<int> (wordViewList.size());

// add to data
const auto wordStart = static_cast<uint32_t> (wordData.size());
wordData.insert (wordData.end(), word.begin(), word.end());

// add word view
const auto newWordView = WordView { wordStart, static_cast<uint32_t> (wordData.size()) };
wordHist.emplace_back (word);
wordViewList.emplace_back (newWordView);
wordMap.insert ({ std::string { getString (newWordView) }, newWordIndex });

// return word-index
return newWordIndex;
}
};
} // namespace chowdsp::search_database
Loading
Loading