Optimizing search, buggy BlockArena on emscripten, cleanup MergeSort, address sanitizer, compile web on linux
This commit is contained in:
@@ -27,13 +27,13 @@ void CommandWindowLayout(Rect2I *rect, Int wx, Int wy) {
|
||||
n->document_rect = n->total_rect = CutBottom(rect, barsize);
|
||||
}
|
||||
|
||||
Int FuzzyRate(String16 string, String16 with) {
|
||||
int32_t FuzzyRate(String16 string, String16 with) {
|
||||
ProfileFunction();
|
||||
if (with.len == 0) return 0;
|
||||
Int points = 0;
|
||||
Int consecutive = 0;
|
||||
Int with_i = 0;
|
||||
for (Int i = 0; i < string.len; i++) {
|
||||
int32_t points = 0;
|
||||
int32_t consecutive = 0;
|
||||
int32_t with_i = 0;
|
||||
for (int32_t i = 0; i < string.len; i++) {
|
||||
if (ToLowerCase(string.data[i]) == ToLowerCase(with[with_i])) {
|
||||
consecutive += 1;
|
||||
with_i += 1;
|
||||
@@ -49,33 +49,25 @@ Int FuzzyRate(String16 string, String16 with) {
|
||||
return points;
|
||||
}
|
||||
|
||||
inline bool MergeSortCompare(FuzzyPair *a, FuzzyPair *b) {
|
||||
bool result = a->rating > b->rating;
|
||||
return result;
|
||||
}
|
||||
|
||||
Array<FuzzyPair> FuzzySearchLines(Allocator allocator, Buffer *buffer, Int line_min, Int line_max, String16 needle) {
|
||||
ProfileFunction();
|
||||
if (line_min < 0 || line_min >= buffer->line_starts.len) return {};
|
||||
if (line_max < 0 || line_min > buffer->line_starts.len) return {};
|
||||
Array<FuzzyPair> ratings = {allocator};
|
||||
Reserve(&ratings, line_max - line_min + 4);
|
||||
for (Int i = line_min; i < line_max; i += 1) {
|
||||
String16 s = GetLineStringWithoutNL(buffer, i);
|
||||
Int idx = 0;
|
||||
if (Seek(s, u" || ", &idx)) {
|
||||
s.len = idx;
|
||||
}
|
||||
s = Trim(s);
|
||||
Int rating = FuzzyRate(s, needle);
|
||||
Add(&ratings, {i, rating});
|
||||
}
|
||||
|
||||
// bubble sort
|
||||
for (Int i = 0; i < ratings.len - 1; i++) {
|
||||
for (Int j = 0; j < ratings.len - 1; j++) {
|
||||
if (ratings[j].rating > ratings[j + 1].rating) {
|
||||
FuzzyPair temp = ratings[j];
|
||||
ratings[j] = ratings[j + 1];
|
||||
ratings[j + 1] = temp;
|
||||
}
|
||||
}
|
||||
int32_t rating = FuzzyRate(s, needle);
|
||||
Add(&ratings, {(int32_t)i, rating});
|
||||
}
|
||||
|
||||
Array<FuzzyPair> temp = Copy(allocator, ratings);
|
||||
MergeSort(ratings.len, ratings.data, temp.data);
|
||||
return ratings;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user