Skip to content

Commit 2e4fca5

Browse files
committed
chore: run prettier
1 parent 89d513c commit 2e4fca5

13 files changed

+468
-453
lines changed

.clang-format

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ BreakConstructorInitializers: BeforeColon
4141
BreakConstructorInitializersBeforeComma: false
4242
BreakStringLiterals: true
4343
ColumnLimit: 0
44-
CommentPragmas: '^ IWYU pragma:'
44+
CommentPragmas: "^ IWYU pragma:"
4545
CompactNamespaces: false
4646
ConstructorInitializerAllOnOneLineOrOnePerLine: false
4747
ConstructorInitializerIndentWidth: 2
@@ -52,16 +52,16 @@ DisableFormat: false
5252
ExperimentalAutoDetectBinPacking: true
5353
FixNamespaceComments: true
5454
ForEachMacros:
55-
- foreach
56-
- Q_FOREACH
57-
- BOOST_FOREACH
55+
- foreach
56+
- Q_FOREACH
57+
- BOOST_FOREACH
5858
IncludeCategories:
59-
- Priority: 2
60-
Regex: ^"(llvm|llvm-c|clang|clang-c)/
61-
- Priority: 3
62-
Regex: ^(<|"(gtest|gmock|isl|json)/)
63-
- Priority: 1
64-
Regex: .*
59+
- Priority: 2
60+
Regex: ^"(llvm|llvm-c|clang|clang-c)/
61+
- Priority: 3
62+
Regex: ^(<|"(gtest|gmock|isl|json)/)
63+
- Priority: 1
64+
Regex: .*
6565
IncludeIsMainRegex: (Test)?$
6666
IndentCaseLabels: false
6767
IndentWidth: 4
@@ -70,8 +70,8 @@ JavaScriptQuotes: Leave
7070
JavaScriptWrapImports: true
7171
KeepEmptyLinesAtTheStartOfBlocks: true
7272
Language: Cpp
73-
MacroBlockBegin: ''
74-
MacroBlockEnd: ''
73+
MacroBlockBegin: ""
74+
MacroBlockEnd: ""
7575
MaxEmptyLinesToKeep: 2
7676
NamespaceIndentation: Inner
7777
ObjCBlockIndentWidth: 7

.clang-tidy

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
---
2-
Checks: '*, -clang-diagnostics-*-compat, -cppcoreguidelines-init-variables, -modernize-return-braced-init-list, -misc-unused-parameters, -misc-non-private-member-variables-in-classes, -llvmlibc-*, -llvm-header-guard, -llvm-include-order, -modernize-use-trailing-return-type, -readability-const-return-type, -readability-avoid-const-params-in-decls, -readability-convert-member-functions-to-static, -fuchsia-default-arguments-declarations, -fuchsia-default-arguments-calls, -*-uppercase-literal-suffix, -fuchsia-overloaded-operator, -google-build-using-namespace, -google-global-names-in-headers'
3-
HeaderFilterRegex: '.*'
4-
FormatStyle: none
2+
Checks: "*, -clang-diagnostics-*-compat, -cppcoreguidelines-init-variables, -modernize-return-braced-init-list, -misc-unused-parameters, -misc-non-private-member-variables-in-classes, -llvmlibc-*, -llvm-header-guard, -llvm-include-order, -modernize-use-trailing-return-type, -readability-const-return-type, -readability-avoid-const-params-in-decls, -readability-convert-member-functions-to-static, -fuchsia-default-arguments-declarations, -fuchsia-default-arguments-calls, -*-uppercase-literal-suffix, -fuchsia-overloaded-operator, -google-build-using-namespace, -google-global-names-in-headers"
3+
HeaderFilterRegex: ".*"
4+
FormatStyle: none

README.md

Lines changed: 85 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,30 @@
33
Fast fuzzy-search - the native replacement for `fuzzaldrin-plus`
44

55
# What is fuzzaldrin-plus-fast?
6-
* Fuzzaldrin plus is an awesome library that provides fuzzy-search that is more targeted towards filenames.
7-
* Fuzzaldrin-plus-fast is a rewrite of the library in native C++ to make it fast. The goal is to make it a few hundred millisecond filter times for a dataset with 1M entries. This performance is helpful in Atom's fuzzy finder to open files from large projects such as Chrome/Mozilla.
6+
7+
- Fuzzaldrin plus is an awesome library that provides fuzzy-search that is more targeted towards filenames.
8+
- Fuzzaldrin-plus-fast is a rewrite of the library in native C++ to make it fast. The goal is to make it a few hundred millisecond filter times for a dataset with 1M entries. This performance is helpful in Atom's fuzzy finder to open files from large projects such as Chrome/Mozilla.
89

910
### Extra featuers
11+
1012
Fuzzaldrin-plus-fast:
13+
1114
- provides `filterTree` function which allows to fuzzy filter text in nested tree-like objects.
1215
- allows setting the candidates only once using `ArrayFilterer` and `TreeFilterer` classes, and then, perform `filter` multiple times. This is much more efficient than calling the `filter` or `filterTree` functions directly every time.
1316

1417
# How performance is improved?
18+
1519
Fuzzaldrin-plus-fast achieves 10x-20x performance improvement over Fuzzaldrin plus for chromium project with 300K files. This high performance is achieved using the following techniques.
16-
* Converting Javascript/CoffeeScript code to native C++ bindings provides 4x performance benefit.
17-
* Use multiple threads to parallelize computation to achieve another 4x performance benefit. Currently, up to 8 threads are used if there are more than 10K candidates to filter.
18-
* Some miscellaneous improvements provide additional benefit.
20+
21+
- Converting Javascript/CoffeeScript code to native C++ bindings provides 4x performance benefit.
22+
- Use multiple threads to parallelize computation to achieve another 4x performance benefit. Currently, up to 8 threads are used if there are more than 10K candidates to filter.
23+
- Some miscellaneous improvements provide additional benefit.
1924

2025
This project potentially solves the following Atom fuzzy-finder issues if used.
2126
https://github.com/atom/fuzzy-finder/issues/271 and https://github.com/atom/fuzzy-finder/issues/88
2227

2328
# Is the API the same?
29+
2430
API is backward compatible with Fuzzaldrin and Fuzzaldrin-plus. Additional functions are provided to achieve better performance that could suit your needs
2531

2632
# Usage
@@ -32,21 +38,24 @@ npm install fuzzaldrin-plus-fast
3238
```
3339

3440
To import all the functions:
41+
3542
```js
36-
import * as fuzzaldrin from 'fuzzaldrin-plus-fast'
43+
import * as fuzzaldrin from "fuzzaldrin-plus-fast"
3744
```
45+
3846
or
47+
3948
```js
40-
const fuzzaldrin = require('fuzzaldrin-plus-fast')
49+
const fuzzaldrin = require("fuzzaldrin-plus-fast")
4150
```
4251

4352
### filter(candidates, query, options = {})
4453

4554
Sort and filter the given candidates by matching them against the given query.
4655

47-
* `candidates` - An array of strings or objects.
48-
* `query` - A string query to match each candidate against.
49-
* `options` options. You should provide a `key` in the options if an array of objects are passed.
56+
- `candidates` - An array of strings or objects.
57+
- `query` - A string query to match each candidate against.
58+
- `options` options. You should provide a `key` in the options if an array of objects are passed.
5059

5160
Returns an array of candidates sorted by best match against the query.
5261

@@ -71,26 +80,28 @@ results = filter(candidates, 'me', {key: 'name'}) // [{name: 'Me', id: 2}, {name
7180
### ArrayFilterer class
7281

7382
ArrayFilterer is a class that allows to set the `candidates` only once and perform filtering on them multiple times. This is much more efficient than calling the `filter` function directly.
83+
7484
```typescript
7585
export class ArrayFilterer<T> {
76-
constructor()
77-
78-
/** The method to set the candidates that are going to be filtered
79-
* @param candidates An array of tree objects.
80-
* @param dataKey (optional) if `candidates` is an array of objects, pass the key in the object which holds the data. dataKey can be the options object passed to `filter` method (but this is deprecated).
81-
*/
82-
setCandidates<T>(candidates: Array<T>, dataKey?: string): void
83-
84-
/** The method to perform the filtering on the already set candidates
85-
* @param query A string query to match each candidate against.
86-
* @param options options
87-
* @return returns an array of candidates sorted by best match against the query.
88-
*/
89-
filter(query: string, options: IFilterOptions<T>): Array<T>
86+
constructor()
87+
88+
/** The method to set the candidates that are going to be filtered
89+
* @param candidates An array of tree objects.
90+
* @param dataKey (optional) if `candidates` is an array of objects, pass the key in the object which holds the data. dataKey can be the options object passed to `filter` method (but this is deprecated).
91+
*/
92+
setCandidates<T>(candidates: Array<T>, dataKey?: string): void
93+
94+
/** The method to perform the filtering on the already set candidates
95+
* @param query A string query to match each candidate against.
96+
* @param options options
97+
* @return returns an array of candidates sorted by best match against the query.
98+
*/
99+
filter(query: string, options: IFilterOptions<T>): Array<T>
90100
}
91101
```
92102

93103
Example:
104+
94105
```Javascript
95106
const { ArrayFilterer } = require('fuzzaldrin-plus-fast')
96107

@@ -107,59 +118,57 @@ Sort and filter the given Tree candidates by matching them against the given que
107118

108119
A **tree object** is an object in which each entry stores the data in its dataKey and it has (may have) some children (with a similar structure) in its childrenKey. See the following example.
109120

110-
* `candidates` An array of tree objects.
111-
* `query` A string query to match each candidate against.
112-
* `dataKey` the key of the object (and its children) which holds the data
113-
* `childrenKey` the key of the object (and its children) which hold the children
114-
* `options` options
115-
* `returns` An array of candidate objects in form of `{data, index, level}` sorted by best match against the query. Each objects has the address of the object in the tree using `index` and `level`.
121+
- `candidates` An array of tree objects.
122+
- `query` A string query to match each candidate against.
123+
- `dataKey` the key of the object (and its children) which holds the data
124+
- `childrenKey` the key of the object (and its children) which hold the children
125+
- `options` options
126+
- `returns` An array of candidate objects in form of `{data, index, level}` sorted by best match against the query. Each objects has the address of the object in the tree using `index` and `level`.
116127

117128
```js
118-
const { filterTree } = require('fuzzaldrin-plus-fast')
129+
const { filterTree } = require("fuzzaldrin-plus-fast")
119130

120131
candidates = [
121-
{data: "bye1", children: [{data: "hello"}]},
122-
{data: "Bye2", children: [{data: "_bye4"}, {data: "hel"}]},
123-
{data: "eye"},
132+
{ data: "bye1", children: [{ data: "hello" }] },
133+
{ data: "Bye2", children: [{ data: "_bye4" }, { data: "hel" }] },
134+
{ data: "eye" },
124135
]
125136

126137
filterTree(candidates, "he", "data", "children") // [ { data: 'hel', index: 1, level: 1 }, { data: 'hello', index: 0, level: 1 }]
127138

128139
// With an array of objects (similar to providing `key` to `filter` function)
129-
const candidates = [
130-
{data: "helloworld"},
131-
{data: "bye"},
132-
{data: "hello"},
133-
]
134-
results = filter(candidates, 'hello', {key: 'name'}) // [ { data: 'hello', index: 2, level: 0 }, { data: 'helloworld', index: 0, level: 0 } ]
140+
const candidates = [{ data: "helloworld" }, { data: "bye" }, { data: "hello" }]
141+
results = filter(candidates, "hello", { key: "name" }) // [ { data: 'hello', index: 2, level: 0 }, { data: 'helloworld', index: 0, level: 0 } ]
135142
```
136143

137144
**Performance Note**: use `TreeFilterer` class if you call the `filterTree` function multiple times on a certain set of candidates. `filterTree` internally uses this class, however, in each call it sets the candidates from scratch which can slow down the process.
138145

139146
### TreeFilterer class
147+
140148
`TreeFilterer` is a class that allows to set the `candidates` only once and perform filtering on them multiple times. This is much more efficient than calling the `filterTree` function directly.
141149

142150
```typescript
143151
export class TreeFilterer<T> {
144-
constructor()
145-
146-
/** The method to set the candidates that are going to be filtered
147-
* @param candidates An array of tree objects.
148-
* @param dataKey the key of the object (and its children) which holds the data (defaults to `"data"`)
149-
* @param childrenKey the key of the object (and its children) which hold the children (defaults to `"children"`)
150-
*/
151-
setCandidates<T>(candidates: Array<T>, dataKey?: string, childrenKey?: string): void
152-
153-
/** The method to perform the filtering on the already set candidates
154-
* @param query A string query to match each candidate against.
155-
* @param options options
156-
* @return An array of candidate objects in form of `{data, index, level}` sorted by best match against the query. Each objects has the address of the object in the tree using `index` and `level`.
157-
*/
158-
filter(query: string, options: IFilterOptions<object>): TreeFilterResult[]
152+
constructor()
153+
154+
/** The method to set the candidates that are going to be filtered
155+
* @param candidates An array of tree objects.
156+
* @param dataKey the key of the object (and its children) which holds the data (defaults to `"data"`)
157+
* @param childrenKey the key of the object (and its children) which hold the children (defaults to `"children"`)
158+
*/
159+
setCandidates<T>(candidates: Array<T>, dataKey?: string, childrenKey?: string): void
160+
161+
/** The method to perform the filtering on the already set candidates
162+
* @param query A string query to match each candidate against.
163+
* @param options options
164+
* @return An array of candidate objects in form of `{data, index, level}` sorted by best match against the query. Each objects has the address of the object in the tree using `index` and `level`.
165+
*/
166+
filter(query: string, options: IFilterOptions<object>): TreeFilterResult[]
159167
}
160168
```
161169

162170
Example:
171+
163172
```Javascript
164173
const { TreeFilterer } = require('fuzzaldrin-plus-fast')
165174

@@ -181,8 +190,8 @@ arrayFilterer.filter('bye')
181190

182191
Score the given string against the given query.
183192

184-
* `string` - The string the score.
185-
* `query` - The query to score the string against.
193+
- `string` - The string the score.
194+
- `query` - The query to score the string against.
186195

187196
```js
188197
const { score } = require('fuzzaldrin-plus-fast')
@@ -192,28 +201,37 @@ score('Maybe', 'me') # 0.0693
192201
```
193202

194203
### match (string, query, options = {})
204+
195205
Gives an array of indices at which the query matches the given string
206+
196207
```js
197-
const { match } = require('fuzzaldrin-plus-fast')
208+
const { match } = require("fuzzaldrin-plus-fast")
198209

199-
match('Hello World', 'he') // [0, 1]
200-
match('Hello World', 'wor') // [6, 7, 8]
201-
match('Hello World', 'elwor') // [1, 2, 6, 7, 8]
210+
match("Hello World", "he") // [0, 1]
211+
match("Hello World", "wor") // [6, 7, 8]
212+
match("Hello World", "elwor") // [1, 2, 6, 7, 8]
202213
```
203214

204215
### wrap (string, query, options = {})
216+
205217
Gives an HTML/Markdown string that highlights the range for which the match happens
218+
206219
```js
207-
wrap("helloworld", "he")
220+
wrap("helloworld", "he")
208221
```
222+
209223
<strong class="highlight">he</strong>lloworld
224+
210225
```js
211226
wrap("Hello world", "he")
212227
```
228+
213229
<strong class="highlight">He</strong>llo world
214230

215231
### options
232+
216233
In all the above functions, you can pass an optional object with the following keys
234+
217235
```typescript
218236
{
219237
/** only for `filter` function */
@@ -237,11 +255,13 @@ In all the above functions, you can pass an optional object with the following k
237255
```
238256

239257
# Info for Developers
258+
240259
## How to release the package to npm?
241260

242-
* Bump up version in package.json.
243-
* Create a new release tag in Github, for the bumped version. This should trigger builds in GitHub Actions. The binaries will be uploaded to the action's page.
244-
* Manually download the prebuilt binaries from GitHub and publish.
261+
- Bump up version in package.json.
262+
- Create a new release tag in Github, for the bumped version. This should trigger builds in GitHub Actions. The binaries will be uploaded to the action's page.
263+
- Manually download the prebuilt binaries from GitHub and publish.
264+
245265
```
246266
npm publish
247267
```

0 commit comments

Comments
 (0)