44 constexpr
int deletion_cost = 1;
45 constexpr
int insertion_cost = 1;
46 constexpr
int substitution_cost = 1;
47 constexpr
int transposition_cost = 1;
56 const int row_length = size_b + 1;
66 v1[i] = i * insertion_cost;
72 v2[0] = (i + 1) * deletion_cost;
83 int new_cost =
std::min({
v1[j + 1] + deletion_cost,
84 v2[j] + insertion_cost,
85 v1[j] + (unicode_a != unicode_b) * substitution_cost});
87 if (unicode_a == prev_unicode_b && prev_unicode_a == unicode_b) {
88 new_cost =
std::min(new_cost, v0[j - 1] + transposition_cost);
93 prev_unicode_b = unicode_b;
99 prev_unicode_a = unicode_a;
120 if (query_size == 1) {
126 const int max_errors = query_size <= 1 ? 0 : query_size / 8 + 1;
129 if (query_size - full_size > max_errors) {
137 const char *full_begin = full.
begin();
138 const char *full_end = full.
end();
140 const char *window_begin = full_begin;
141 const char *window_end = window_begin;
142 const int window_size =
std::min(query_size + max_errors, full_size);
143 const int extra_chars = window_size - query_size;
144 const int max_acceptable_distance = max_errors + extra_chars;
146 for (
int i = 0; i < window_size; i++) {
151 StringRef window{window_begin, window_end};
156 if (
ELEM(window_begin_unicode, query_first_unicode, query_second_unicode)) {
158 if (
distance <= max_acceptable_distance) {
162 if (window_end == full_end) {
169 for (
int i = 0; i < window_offset && window_end < full_end; i++) {
192 if (start >= words.
size()) {
196 r_word_is_matched.
fill(
false);
198 size_t query_index = 0;
199 int word_index = start;
200 size_t char_index = 0;
202 int first_found_word_index = -1;
204 while (query_index <
query.size()) {
209 if (word_index >= words.
size()) {
210 if (first_found_word_index >= 0) {
214 query, words, word_is_usable, r_word_is_matched, first_found_word_index + 1);
220 if (!word_is_usable[word_index]) {
228 if (
static_cast<int>(char_index) < word.
size()) {
231 if (query_unicode == char_unicode) {
232 r_word_is_matched[word_index] =
true;
233 if (first_found_word_index == -1) {
234 first_found_word_index = word_index;
253 int best_word_index = -1;
255 if (!word_is_usable[i]) {
260 if (word.
size() < best_word_size) {
262 best_word_size = word.
size();
266 return best_word_index;
275 if (!word_is_usable[i]) {
280 if (error_count >= 0) {
281 *r_error_count = error_count;
298 int total_match_score = 1000;
300 for (
StringRef query_word : query_words) {
304 query_word, result_words, word_is_usable);
305 if (word_index >= 0) {
306 total_match_score += 10;
307 word_is_usable[word_index] =
false;
315 query_word, result_words, word_is_usable, matched_words);
317 total_match_score += 3;
319 if (matched_words[i]) {
320 word_is_usable[i] =
false;
330 query_word, result_words, word_is_usable, &error_count);
331 if (word_index >= 0) {
332 total_match_score += 3 - error_count;
333 word_is_usable[word_index] =
false;
342 return total_match_score;
356 auto is_separator = [&](
uint32_t unicode) {
357 return ELEM(unicode, unicode_space, unicode_right_triangle);
362 char *mutable_copy =
const_cast<char *
>(str_copy.
data());
363 const size_t str_size_in_bytes =
static_cast<size_t>(
str.size());
367 bool is_in_word =
false;
368 size_t word_start = 0;
370 while (offset < str_size_in_bytes) {
373 if (is_separator(unicode)) {
376 str_copy.
substr(
static_cast<int>(word_start),
static_cast<int>(offset - word_start)));
445 query_words, search->
items[result_index].normalized_words);
447 result_indices_by_score.
add(score, result_index);
452 for (
const int score : result_indices_by_score.
keys()) {
453 found_scores.
append(score);
460 for (
const int score : found_scores) {
462 if (score == found_scores[0] && !query_str.
is_empty()) {
467 return search->items[a].length < search->items[b].length;
473 void **sorted_data =
static_cast<void **
>(
475 for (
const int i : sorted_result_indices.
index_range()) {
476 const int result_index = sorted_result_indices[i];
481 *r_data = sorted_data;
483 return sorted_result_indices.
size();
488 delete string_search;
void BLI_str_tolower_ascii(char *str, const size_t len) ATTR_NONNULL()
struct StringSearch StringSearch
int BLI_str_utf8_size(const char *p) ATTR_NONNULL()
unsigned int BLI_str_utf8_as_unicode_and_size(const char *__restrict p, size_t *__restrict index) ATTR_NONNULL()
unsigned int BLI_str_utf8_as_unicode(const char *p) ATTR_NONNULL()
size_t BLI_strnlen_utf8(const char *strc, const size_t maxlen) ATTR_NONNULL()
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei GLsizei GLenum type _GL_VOID_RET _GL_VOID GLsizei GLenum GLenum const void *pixels _GL_VOID_RET _GL_VOID const void *pointer _GL_VOID_RET _GL_VOID GLdouble v _GL_VOID_RET _GL_VOID GLfloat v _GL_VOID_RET _GL_VOID GLint GLint i2 _GL_VOID_RET _GL_VOID GLint j _GL_VOID_RET _GL_VOID GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble GLdouble GLdouble zFar _GL_VOID_RET _GL_UINT GLdouble *equation _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLenum query
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei GLsizei GLenum type _GL_VOID_RET _GL_VOID GLsizei GLenum GLenum const void *pixels _GL_VOID_RET _GL_VOID const void *pointer _GL_VOID_RET _GL_VOID GLdouble v _GL_VOID_RET _GL_VOID GLfloat v _GL_VOID_RET _GL_VOID GLint GLint i2 _GL_VOID_RET _GL_VOID GLint j _GL_VOID_RET _GL_VOID GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble GLdouble GLdouble zFar _GL_VOID_RET _GL_UINT GLdouble *equation _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLenum GLfloat *v _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLfloat *values _GL_VOID_RET _GL_VOID GLushort *values _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLenum GLdouble *params _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_BOOL GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLushort pattern _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint GLdouble v1
ATTR_WARN_UNUSED_RESULT const BMVert * v2
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
void sort(btMatrix3x3 &U, btVector3 &sigma, btMatrix3x3 &V, int t)
Helper function of 3X3 SVD for sorting singular values.
MutableSpan< T > construct_array_copy(Span< T > src)
StringRefNull copy_string(StringRef str)
MapType::KeyIterator keys() const
Span< Value > lookup(const Key &key) const
void add(const Key &key, const Value &value)
constexpr void fill(const T &value)
constexpr int64_t size() const
constexpr IndexRange index_range() const
constexpr const char * data() const
static constexpr int64_t not_found
constexpr int64_t find(char c, int64_t pos=0) const
constexpr bool is_empty() const
constexpr const char * end() const
constexpr const char * begin() const
constexpr bool startswith(StringRef prefix) const
constexpr StringRef substr(int64_t start, const int64_t size) const
constexpr int64_t size() const
constexpr StringRef drop_prefix(const int64_t n) const
void append(const T &value)
Span< T > as_span() const
IndexRange index_range() const
void extend(Span< T > array)
void *(* MEM_malloc_arrayN)(size_t len, size_t size, const char *str)
void extract_normalized_words(StringRef str, LinearAllocator<> &allocator, Vector< StringRef, 64 > &r_words)
static int get_shortest_word_index_that_startswith(StringRef query, Span< StringRef > words, Span< bool > word_is_usable)
static bool match_word_initials(StringRef query, Span< StringRef > words, Span< bool > word_is_usable, MutableSpan< bool > r_word_is_matched, int start=0)
static int64_t count_utf8_code_points(StringRef str)
static int get_word_index_that_fuzzy_matches(StringRef query, Span< StringRef > words, Span< bool > word_is_usable, int *r_error_count)
int get_fuzzy_match_errors(StringRef query, StringRef full)
static int score_query_against_words(Span< StringRef > query_words, Span< StringRef > result_words)
int damerau_levenshtein_distance(StringRef a, StringRef b)
StringSearch * BLI_string_search_new()
void BLI_string_search_add(StringSearch *search, const char *str, void *user_data)
int BLI_string_search_query(StringSearch *search, const char *query, void ***r_data)
void BLI_string_search_free(StringSearch *string_search)
blender::Span< blender::StringRef > normalized_words
blender::Vector< SearchItem > items
blender::LinearAllocator allocator
ccl_device_inline float distance(const float2 &a, const float2 &b)