├── .nvmrc ├── .watchmanconfig ├── example ├── .watchmanconfig ├── jest.config.js ├── .bundle │ └── config ├── app.json ├── ios │ ├── File.swift │ ├── FastUrlExample │ │ ├── Images.xcassets │ │ │ ├── Contents.json │ │ │ └── AppIcon.appiconset │ │ │ │ └── Contents.json │ │ ├── AppDelegate.h │ │ ├── main.m │ │ ├── AppDelegate.mm │ │ ├── Info.plist │ │ └── LaunchScreen.storyboard.xml │ ├── FastTrieExample-Bridging-Header.h │ ├── FastTrieExample.xcworkspace │ │ ├── contents.xcworkspacedata │ │ ├── xcshareddata │ │ │ └── IDEWorkspaceChecks.plist │ │ └── contents.xcworkspacedata.xml │ ├── .xcode.env │ ├── FastTrieExampleTests │ │ ├── Info.plist │ │ └── FastUrlExampleTests.m │ ├── FastTrieExample.xcodeproj │ │ └── xcshareddata │ │ │ └── xcschemes │ │ │ ├── FastTrieExampleTests.xcscheme │ │ │ ├── FastTrieExample.xcscheme │ │ │ └── FastUrlExample.xcscheme.xml │ └── Podfile ├── android │ ├── app │ │ ├── debug.keystore │ │ ├── src │ │ │ ├── main │ │ │ │ ├── res │ │ │ │ │ ├── values │ │ │ │ │ │ ├── strings.xml │ │ │ │ │ │ └── styles.xml │ │ │ │ │ ├── mipmap-hdpi │ │ │ │ │ │ ├── ic_launcher.png │ │ │ │ │ │ └── ic_launcher_round.png │ │ │ │ │ ├── mipmap-mdpi │ │ │ │ │ │ ├── ic_launcher.png │ │ │ │ │ │ └── ic_launcher_round.png │ │ │ │ │ ├── mipmap-xhdpi │ │ │ │ │ │ ├── ic_launcher.png │ │ │ │ │ │ └── ic_launcher_round.png │ │ │ │ │ ├── mipmap-xxhdpi │ │ │ │ │ │ ├── ic_launcher.png │ │ │ │ │ │ └── ic_launcher_round.png │ │ │ │ │ ├── mipmap-xxxhdpi │ │ │ │ │ │ ├── ic_launcher.png │ │ │ │ │ │ └── ic_launcher_round.png │ │ │ │ │ └── drawable │ │ │ │ │ │ └── rn_edit_text_material.xml │ │ │ │ ├── AndroidManifest.xml │ │ │ │ └── java │ │ │ │ │ └── com │ │ │ │ │ └── fasttrieexample │ │ │ │ │ ├── MainActivity.java │ │ │ │ │ └── MainApplication.java │ │ │ ├── debug │ │ │ │ ├── AndroidManifest.xml │ │ │ │ └── java │ │ │ │ │ └── com │ │ │ │ │ └── fasttrieexample │ │ │ │ │ └── ReactNativeFlipper.java │ │ │ └── release │ │ │ │ └── java │ │ │ │ └── com │ │ │ │ └── fasttrieexample │ │ │ │ └── ReactNativeFlipper.java │ │ ├── proguard-rules.pro │ │ └── build.gradle │ ├── gradle │ │ └── wrapper │ │ │ ├── gradle-wrapper.jar │ │ │ └── gradle-wrapper.properties │ ├── settings.gradle │ ├── build.gradle │ ├── gradle.properties │ ├── gradlew.bat │ └── gradlew ├── Gemfile ├── react-native.config.js ├── src │ ├── screens │ │ ├── params.ts │ │ ├── Tests │ │ │ ├── types.ts │ │ │ ├── testList.tsx │ │ │ ├── tests │ │ │ │ ├── configurationAndErrorHandlingTests.ts │ │ │ │ ├── deletionTests.ts │ │ │ │ ├── insertionTests.ts │ │ │ │ └── findAndContainsTests.ts │ │ │ └── Tests.tsx │ │ ├── Benchmarks │ │ │ ├── benchmarks │ │ │ │ ├── bench.ts │ │ │ │ ├── find.ts │ │ │ │ ├── contains.ts │ │ │ │ ├── insert.ts │ │ │ │ └── utils.ts │ │ │ ├── Benchmarks.tsx │ │ │ ├── SpeedBenchmarks.tsx │ │ │ └── MemoryBenchmarks.tsx │ │ └── Home.tsx │ ├── JsTrie.ts │ ├── components │ │ ├── Text.tsx │ │ ├── Indentator.tsx │ │ ├── Button.tsx │ │ ├── Suite.tsx │ │ ├── CorrectResultItem.tsx │ │ ├── IncorrectResultItem.tsx │ │ ├── NavigationButton.tsx │ │ └── TestItem.tsx │ ├── wordlists │ │ └── allWordlists.ts │ ├── testing │ │ ├── MochaRnAdapter.ts │ │ └── MochaSetup.ts │ ├── App.tsx │ └── Trie.ts ├── index.js ├── babel.config.js ├── metro.config.js ├── package.json └── README.md ├── .gitattributes ├── tsconfig.build.json ├── babel.config.js ├── benchmarks ├── iphone_7.jpeg ├── pixel_3a.jpeg ├── pixel_5.jpeg ├── galaxy_a10e.jpeg ├── iphone_11_pro_max.jpeg └── iphone_15_pro_max.jpeg ├── android ├── src │ └── main │ │ ├── AndroidManifestNew.xml │ │ ├── AndroidManifest.xml │ │ └── java │ │ └── com │ │ └── fasturl │ │ ├── FastTrieBridge.java │ │ ├── FastTriePackage.java │ │ └── FastTrieModule.java ├── gradle.properties ├── CMakeLists.txt ├── cpp-adapter.cpp └── build.gradle ├── cpp ├── fast-trie.h ├── utils.h ├── TrieHostObject.h ├── fast-trie.cpp ├── TrieHostObject.cpp └── tsl │ ├── array-hash │ └── array_growth_policy.h │ └── htrie_set.h ├── ios ├── FastTrie.h └── FastTrie.mm ├── lefthook.yml ├── .editorconfig ├── .yarnrc.yml ├── tsconfig.json ├── turbo.json ├── scripts └── pod-install.cjs ├── .gitignore ├── LICENSE ├── react-native-fast-trie.podspec ├── src └── index.tsx ├── package.json ├── CONTRIBUTING.md ├── README.md └── CODE_OF_CONDUCT.md /.nvmrc: -------------------------------------------------------------------------------- 1 | v18 2 | -------------------------------------------------------------------------------- /.watchmanconfig: -------------------------------------------------------------------------------- 1 | {} -------------------------------------------------------------------------------- /example/.watchmanconfig: -------------------------------------------------------------------------------- 1 | {} 2 | -------------------------------------------------------------------------------- /example/jest.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | preset: 'react-native', 3 | }; 4 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | *.pbxproj -text 2 | # specific for windows script files 3 | *.bat text eol=crlf -------------------------------------------------------------------------------- /example/.bundle/config: -------------------------------------------------------------------------------- 1 | BUNDLE_PATH: "vendor/bundle" 2 | BUNDLE_FORCE_RUBY_PLATFORM: 1 3 | -------------------------------------------------------------------------------- /tsconfig.build.json: -------------------------------------------------------------------------------- 1 | 2 | { 3 | "extends": "./tsconfig", 4 | "exclude": ["example"] 5 | } 6 | -------------------------------------------------------------------------------- /example/app.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "FastTrieExample", 3 | "displayName": "FastTrieExample" 4 | } 5 | -------------------------------------------------------------------------------- /babel.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | presets: ['module:metro-react-native-babel-preset'], 3 | }; 4 | -------------------------------------------------------------------------------- /example/ios/File.swift: -------------------------------------------------------------------------------- 1 | // 2 | // File.swift 3 | // FastTrieExample 4 | // 5 | 6 | import Foundation 7 | -------------------------------------------------------------------------------- /benchmarks/iphone_7.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zacharyfmarion/react-native-fast-trie/HEAD/benchmarks/iphone_7.jpeg -------------------------------------------------------------------------------- /benchmarks/pixel_3a.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zacharyfmarion/react-native-fast-trie/HEAD/benchmarks/pixel_3a.jpeg -------------------------------------------------------------------------------- /benchmarks/pixel_5.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zacharyfmarion/react-native-fast-trie/HEAD/benchmarks/pixel_5.jpeg -------------------------------------------------------------------------------- /benchmarks/galaxy_a10e.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zacharyfmarion/react-native-fast-trie/HEAD/benchmarks/galaxy_a10e.jpeg -------------------------------------------------------------------------------- /android/src/main/AndroidManifestNew.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /benchmarks/iphone_11_pro_max.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zacharyfmarion/react-native-fast-trie/HEAD/benchmarks/iphone_11_pro_max.jpeg -------------------------------------------------------------------------------- /benchmarks/iphone_15_pro_max.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zacharyfmarion/react-native-fast-trie/HEAD/benchmarks/iphone_15_pro_max.jpeg -------------------------------------------------------------------------------- /example/android/app/debug.keystore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zacharyfmarion/react-native-fast-trie/HEAD/example/android/app/debug.keystore -------------------------------------------------------------------------------- /example/android/app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | FastTrieExample 3 | 4 | -------------------------------------------------------------------------------- /example/ios/FastUrlExample/Images.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /android/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | -------------------------------------------------------------------------------- /example/ios/FastTrieExample-Bridging-Header.h: -------------------------------------------------------------------------------- 1 | // 2 | // Use this file to import your target's public headers that you would like to expose to Swift. 3 | // 4 | -------------------------------------------------------------------------------- /example/ios/FastUrlExample/AppDelegate.h: -------------------------------------------------------------------------------- 1 | #import 2 | #import 3 | 4 | @interface AppDelegate : RCTAppDelegate 5 | 6 | @end 7 | -------------------------------------------------------------------------------- /example/android/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zacharyfmarion/react-native-fast-trie/HEAD/example/android/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /android/gradle.properties: -------------------------------------------------------------------------------- 1 | FastTrie_kotlinVersion=1.7.0 2 | FastTrie_minSdkVersion=21 3 | FastTrie_targetSdkVersion=31 4 | FastTrie_compileSdkVersion=31 5 | FastTrie_ndkversion=21.4.7075529 6 | -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zacharyfmarion/react-native-fast-trie/HEAD/example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zacharyfmarion/react-native-fast-trie/HEAD/example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zacharyfmarion/react-native-fast-trie/HEAD/example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zacharyfmarion/react-native-fast-trie/HEAD/example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zacharyfmarion/react-native-fast-trie/HEAD/example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zacharyfmarion/react-native-fast-trie/HEAD/example/android/app/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zacharyfmarion/react-native-fast-trie/HEAD/example/android/app/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zacharyfmarion/react-native-fast-trie/HEAD/example/android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zacharyfmarion/react-native-fast-trie/HEAD/example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zacharyfmarion/react-native-fast-trie/HEAD/example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /cpp/fast-trie.h: -------------------------------------------------------------------------------- 1 | #ifndef FASTTRIE_H 2 | #define FASTTRIE_H 3 | 4 | #include "utils.h" 5 | 6 | namespace fasttrie { 7 | void install(facebook::jsi::Runtime &runtime); 8 | } 9 | 10 | #endif /* FASTTRIE_H */ 11 | -------------------------------------------------------------------------------- /example/Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | # You may use http://rbenv.org/ or https://rvm.io/ to install and use this version 4 | ruby ">= 2.6.10" 5 | 6 | gem 'cocoapods', '~> 1.13' 7 | gem 'activesupport', '>= 6.1.7.3', '< 7.1.0' 8 | -------------------------------------------------------------------------------- /example/react-native.config.js: -------------------------------------------------------------------------------- 1 | const path = require('path'); 2 | const pak = require('../package.json'); 3 | 4 | module.exports = { 5 | dependencies: { 6 | [pak.name]: { 7 | root: path.join(__dirname, '..'), 8 | }, 9 | }, 10 | }; 11 | -------------------------------------------------------------------------------- /example/ios/FastUrlExample/main.m: -------------------------------------------------------------------------------- 1 | #import 2 | 3 | #import "AppDelegate.h" 4 | 5 | int main(int argc, char *argv[]) 6 | { 7 | @autoreleasepool { 8 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /example/android/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.0.1-all.zip 4 | networkTimeout=10000 5 | zipStoreBase=GRADLE_USER_HOME 6 | zipStorePath=wrapper/dists 7 | -------------------------------------------------------------------------------- /example/android/settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'FastTrieExample' 2 | apply from: file("../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesSettingsGradle(settings) 3 | include ':app' 4 | includeBuild('../node_modules/@react-native/gradle-plugin') 5 | -------------------------------------------------------------------------------- /example/src/screens/params.ts: -------------------------------------------------------------------------------- 1 | export type TestingScreenProps = { 2 | testRegistrators: Array<() => void>; 3 | }; 4 | 5 | export type RootStackParamList = { 6 | Home: undefined; 7 | Benchmarks: undefined; 8 | SpeedBenchmarks: undefined; 9 | MemoryBenchmarks: undefined; 10 | Tests: TestingScreenProps; 11 | }; 12 | -------------------------------------------------------------------------------- /example/ios/FastTrieExample.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /example/ios/FastTrieExample.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /ios/FastTrie.h: -------------------------------------------------------------------------------- 1 | #ifdef __cplusplus 2 | #import "fast-trie.h" 3 | #endif 4 | 5 | #ifdef RCT_NEW_ARCH_ENABLED 6 | #import "RNFasTrieSpec.h" 7 | 8 | @interface FastTrie : NSObject 9 | #else 10 | #import 11 | 12 | @interface FastTrie : NSObject 13 | #endif 14 | 15 | @end 16 | -------------------------------------------------------------------------------- /example/src/screens/Tests/types.ts: -------------------------------------------------------------------------------- 1 | export type RowItemType = { 2 | type: 'correct' | 'incorrect' | 'grouping'; 3 | description: string; 4 | errorMsg?: string; 5 | indentation: number; 6 | key: string; 7 | }; 8 | 9 | export type TestItemType = { 10 | description: string; 11 | registrator: () => void; 12 | value: boolean; 13 | }; 14 | -------------------------------------------------------------------------------- /lefthook.yml: -------------------------------------------------------------------------------- 1 | pre-commit: 2 | parallel: true 3 | commands: 4 | lint: 5 | glob: "*.{js,ts,jsx,tsx}" 6 | run: npx eslint {staged_files} 7 | types: 8 | glob: "*.{js,ts, jsx, tsx}" 9 | run: npx tsc --noEmit 10 | commit-msg: 11 | parallel: true 12 | commands: 13 | commitlint: 14 | run: npx commitlint --edit 15 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # EditorConfig helps developers define and maintain consistent 2 | # coding styles between different editors and IDEs 3 | # editorconfig.org 4 | 5 | root = true 6 | 7 | [*] 8 | 9 | indent_style = space 10 | indent_size = 2 11 | 12 | end_of_line = lf 13 | charset = utf-8 14 | trim_trailing_whitespace = true 15 | insert_final_newline = true 16 | -------------------------------------------------------------------------------- /example/android/app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /.yarnrc.yml: -------------------------------------------------------------------------------- 1 | nodeLinker: node-modules 2 | nmHoistingLimits: workspaces 3 | 4 | plugins: 5 | - path: scripts/pod-install.cjs 6 | - path: .yarn/plugins/@yarnpkg/plugin-interactive-tools.cjs 7 | spec: "@yarnpkg/plugin-interactive-tools" 8 | - path: .yarn/plugins/@yarnpkg/plugin-workspace-tools.cjs 9 | spec: "@yarnpkg/plugin-workspace-tools" 10 | 11 | yarnPath: .yarn/releases/yarn-3.6.1.cjs 12 | -------------------------------------------------------------------------------- /example/index.js: -------------------------------------------------------------------------------- 1 | import { AppRegistry } from 'react-native'; 2 | import App from './src/App'; 3 | import { name as appName } from './app.json'; 4 | import { Buffer } from '@craftzdog/react-native-buffer'; 5 | 6 | global.process = { 7 | cwd: () => 'sxsx', 8 | env: { NODE_ENV: 'production' }, 9 | }; 10 | global.location = {}; 11 | global.Buffer = Buffer; 12 | 13 | AppRegistry.registerComponent(appName, () => App); 14 | -------------------------------------------------------------------------------- /example/babel.config.js: -------------------------------------------------------------------------------- 1 | const path = require('path'); 2 | const pak = require('../package.json'); 3 | 4 | module.exports = { 5 | presets: ['module:metro-react-native-babel-preset'], 6 | plugins: [ 7 | [ 8 | 'module-resolver', 9 | { 10 | extensions: ['.tsx', '.ts', '.js', '.json'], 11 | alias: { 12 | [pak.name]: path.join(__dirname, '..', pak.source), 13 | }, 14 | }, 15 | ], 16 | ], 17 | }; 18 | -------------------------------------------------------------------------------- /example/ios/FastTrieExample.xcworkspace/contents.xcworkspacedata.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 9 | 10 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /example/android/app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /usr/local/Cellar/android-sdk/24.3.3/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | -------------------------------------------------------------------------------- /example/ios/.xcode.env: -------------------------------------------------------------------------------- 1 | # This `.xcode.env` file is versioned and is used to source the environment 2 | # used when running script phases inside Xcode. 3 | # To customize your local environment, you can create an `.xcode.env.local` 4 | # file that is not versioned. 5 | 6 | # NODE_BINARY variable contains the PATH to the node executable. 7 | # 8 | # Customize the NODE_BINARY variable here. 9 | # For example, to use nvm with brew, add the following line 10 | # . "$(brew --prefix nvm)/nvm.sh" --no-use 11 | export NODE_BINARY=$(command -v node) 12 | -------------------------------------------------------------------------------- /example/src/JsTrie.ts: -------------------------------------------------------------------------------- 1 | import { Trie } from 'trie-typed'; 2 | 3 | /** 4 | * Wrapper class for Trie to provide a unified interface 5 | */ 6 | export class JsTrie { 7 | _trie: Trie; 8 | 9 | constructor() { 10 | this._trie = new Trie(); 11 | } 12 | 13 | insert(item: string) { 14 | this._trie.add(item); 15 | } 16 | 17 | contains(item: string) { 18 | return this._trie.has(item); 19 | } 20 | 21 | find(search: string, max: number | undefined = undefined) { 22 | return this._trie.getWords(search, max); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /example/src/screens/Benchmarks/benchmarks/bench.ts: -------------------------------------------------------------------------------- 1 | import { registerBenchmarks as registerContainsBenchmarks } from './contains'; 2 | import { registerBenchmarks as registerInsertBenchmarks } from './insert'; 3 | import { registerBenchmarks as registerFindBenchmarks } from './find'; 4 | 5 | import type { BenchmarkResult } from './utils'; 6 | 7 | export function startBench(): BenchmarkResult[] { 8 | return [ 9 | ...registerInsertBenchmarks(), 10 | ...registerContainsBenchmarks(), 11 | ...registerFindBenchmarks(), 12 | ]; 13 | } 14 | -------------------------------------------------------------------------------- /example/android/app/src/debug/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /cpp/utils.h: -------------------------------------------------------------------------------- 1 | #ifndef FASTTRIE_UTILS_H 2 | #define FASTTRIE_UTILS_H 3 | 4 | #include 5 | 6 | #define HOST_FN(rt, name, functionArgCount, hostFunctionBody) \ 7 | jsi::Function::createFromHostFunction( \ 8 | rt, jsi::PropNameID::forAscii(rt, name), (functionArgCount), \ 9 | [=](jsi::Runtime & rt, const jsi::Value &thisValue, \ 10 | const jsi::Value *arguments, \ 11 | size_t count) -> jsi::Value hostFunctionBody) 12 | 13 | #define HOST_STR(str) jsi::String::createFromAscii(rt, str) 14 | 15 | #endif 16 | -------------------------------------------------------------------------------- /example/src/components/Text.tsx: -------------------------------------------------------------------------------- 1 | import * as React from 'react'; 2 | import { StyleSheet, Text as TextNative } from 'react-native'; 3 | 4 | type Props = { 5 | children: React.ReactNode; 6 | style?: any[]; 7 | }; 8 | 9 | export function Text({ children, style }: Props) { 10 | const styles = React.useMemo(() => { 11 | const res = [textStyles.text]; 12 | if (style) { 13 | res.concat(style); 14 | } 15 | return res; 16 | }, [style]); 17 | 18 | return {children}; 19 | } 20 | 21 | const textStyles = StyleSheet.create({ 22 | text: { 23 | color: 'black', 24 | }, 25 | }); 26 | -------------------------------------------------------------------------------- /cpp/TrieHostObject.h: -------------------------------------------------------------------------------- 1 | #ifndef FASTTRIE_HOSTOBJECT_H 2 | #define FASTTRIE_HOSTOBJECT_H 3 | 4 | #include "utils.h" 5 | #include "tsl/htrie_set.h" 6 | 7 | namespace fasttrie { 8 | namespace jsi = facebook::jsi; 9 | 10 | class JSI_EXPORT TrieHostObject : public jsi::HostObject { 11 | public: 12 | TrieHostObject(size_t burst_threshold, size_t max_load_factor); 13 | 14 | std::vector getPropertyNames(jsi::Runtime &rt); 15 | jsi::Value get(jsi::Runtime &rt, const jsi::PropNameID &propNameID); 16 | 17 | private: 18 | tsl::htrie_set _trie; 19 | }; 20 | 21 | } // namespace fasttrie 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /android/src/main/java/com/fasturl/FastTrieBridge.java: -------------------------------------------------------------------------------- 1 | package com.fasttrie; 2 | 3 | import android.util.Log; 4 | 5 | import com.facebook.react.bridge.ReactApplicationContext; 6 | import com.facebook.react.bridge.ReactContext; 7 | import com.facebook.react.turbomodule.core.CallInvokerHolderImpl; 8 | 9 | public class FastTrieBridge { 10 | private native void installNativeJsi(long jsContextNativePointer); 11 | 12 | public static final FastTrieBridge instance = new FastTrieBridge(); 13 | 14 | public void install(ReactContext context) { 15 | long jsContextPointer = context.getJavaScriptContextHolder().get(); 16 | installNativeJsi(jsContextPointer); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /example/src/wordlists/allWordlists.ts: -------------------------------------------------------------------------------- 1 | import wordlistEN from './wordlist.en'; 2 | import wordlistCZ from './wordlist.cz'; 3 | import wordlistES from './wordlist.es'; 4 | import wordlistFR from './wordlist.fr'; 5 | import wordlistIT from './wordlist.it'; 6 | import wordlistJP from './wordlist.jp'; 7 | import wordlistKR from './wordlist.kr'; 8 | import wordlistPT from './wordlist.pt'; 9 | import wordlistZHCN from './wordlist.zh.cn'; 10 | import wordlistZHTW from './wordlist.zh.tw'; 11 | 12 | export { 13 | wordlistEN, 14 | wordlistCZ, 15 | wordlistES, 16 | wordlistFR, 17 | wordlistIT, 18 | wordlistJP, 19 | wordlistKR, 20 | wordlistPT, 21 | wordlistZHCN, 22 | wordlistZHTW, 23 | }; 24 | -------------------------------------------------------------------------------- /example/android/build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | buildscript { 4 | ext { 5 | buildToolsVersion = "33.0.0" 6 | minSdkVersion = 21 7 | compileSdkVersion = 33 8 | targetSdkVersion = 33 9 | 10 | // We use NDK 23 which has both M1 support and is the side-by-side NDK version from AGP. 11 | ndkVersion = "23.1.7779620" 12 | } 13 | repositories { 14 | google() 15 | mavenCentral() 16 | } 17 | dependencies { 18 | classpath("com.android.tools.build:gradle") 19 | classpath("com.facebook.react:react-native-gradle-plugin") 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /example/src/components/Indentator.tsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import { View, StyleSheet } from 'react-native'; 3 | 4 | type IndentatorProps = { 5 | indentation: number; 6 | children: React.ReactChild; 7 | }; 8 | 9 | export const Indentator: React.FC = ({ 10 | indentation, 11 | children, 12 | }: IndentatorProps) => { 13 | return ( 14 | 15 | 16 | {children} 17 | 18 | ); 19 | }; 20 | 21 | const styles = StyleSheet.create({ 22 | container: { 23 | width: '100%', 24 | padding: 5, 25 | flexDirection: 'row', 26 | alignContent: 'center', 27 | }, 28 | }); 29 | -------------------------------------------------------------------------------- /android/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | project(FastTrie) 2 | cmake_minimum_required(VERSION 3.9.0) 3 | 4 | set(PACKAGE_NAME "fast-trie") 5 | set(CMAKE_VERBOSE_MAKEFILE ON) 6 | set(CMAKE_CXX_STANDARD 17) 7 | set(BUILD_DIR ${CMAKE_SOURCE_DIR}/build) 8 | 9 | # Specifies a path to native header files. 10 | include_directories( 11 | ../cpp 12 | ) 13 | 14 | add_library( 15 | ${PACKAGE_NAME} 16 | SHARED 17 | ../cpp/fast-trie.cpp 18 | ../cpp/TrieHostObject.cpp 19 | cpp-adapter.cpp 20 | ) 21 | 22 | set_target_properties( 23 | ${PACKAGE_NAME} 24 | PROPERTIES CXX_STANDARD 17 25 | CXX_EXTENSIONS OFF 26 | POSITION_INDEPENDENT_CODE ON) 27 | 28 | find_package(ReactAndroid REQUIRED CONFIG) 29 | find_package(fbjni REQUIRED CONFIG) 30 | 31 | target_link_libraries(${PACKAGE_NAME} fbjni::fbjni ReactAndroid::jsi android) 32 | -------------------------------------------------------------------------------- /example/android/app/src/release/java/com/fasttrieexample/ReactNativeFlipper.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | *

This source code is licensed under the MIT license found in the LICENSE file in the root 5 | * directory of this source tree. 6 | */ 7 | package com.fasttrieexample; 8 | 9 | import android.content.Context; 10 | import com.facebook.react.ReactInstanceManager; 11 | 12 | /** 13 | * Class responsible of loading Flipper inside your React Native application. This is the release 14 | * flavor of it so it's empty as we don't want to load Flipper. 15 | */ 16 | public class ReactNativeFlipper { 17 | public static void initializeFlipper(Context context, ReactInstanceManager reactInstanceManager) { 18 | // Do nothing as we don't want to initialize Flipper on Release. 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /example/src/components/Button.tsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import { View, TouchableOpacity, StyleSheet } from 'react-native'; 3 | import { Text } from './Text'; 4 | 5 | type ButtonProps = { 6 | title: string; 7 | onPress: () => void; 8 | }; 9 | 10 | export const Button: React.FC = ({ 11 | title, 12 | onPress, 13 | }: ButtonProps) => { 14 | return ( 15 | 16 | 17 | {title} 18 | 19 | 20 | ); 21 | }; 22 | 23 | const styles = StyleSheet.create({ 24 | container: { 25 | backgroundColor: '#99FFFF', 26 | padding: 10, 27 | borderRadius: 5, 28 | alignContent: 'center', 29 | justifyContent: 'center', 30 | borderWidth: 1, 31 | borderColor: 'black', 32 | }, 33 | }); 34 | -------------------------------------------------------------------------------- /example/src/components/Suite.tsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import { View, StyleSheet } from 'react-native'; 3 | import { Text } from './Text'; 4 | 5 | type SuiteProps = { 6 | description: string; 7 | }; 8 | 9 | export const Suite: React.FC = ({ description }: SuiteProps) => { 10 | const emoji = '↘️ '; 11 | const fullText = emoji + description; 12 | 13 | return ( 14 | 15 | {fullText} 16 | 17 | ); 18 | }; 19 | 20 | const styles = StyleSheet.create({ 21 | scroll: { 22 | flex: 1, 23 | }, 24 | itemContainer: { 25 | borderWidth: 1, 26 | margin: 10, 27 | marginBottom: 0, 28 | flexDirection: 'column', 29 | borderRadius: 5, 30 | padding: 5, 31 | }, 32 | text: { 33 | flexShrink: 1, 34 | }, 35 | }); 36 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "rootDir": ".", 4 | "paths": { 5 | "react-native-fast-trie": ["./src/index"] 6 | }, 7 | "allowUnreachableCode": false, 8 | "allowUnusedLabels": false, 9 | "esModuleInterop": true, 10 | "forceConsistentCasingInFileNames": true, 11 | "jsx": "react", 12 | "lib": ["esnext"], 13 | "module": "esnext", 14 | "moduleResolution": "node", 15 | "noFallthroughCasesInSwitch": true, 16 | "noImplicitReturns": true, 17 | "noImplicitUseStrict": false, 18 | "noStrictGenericChecks": false, 19 | "noUncheckedIndexedAccess": true, 20 | "noUnusedLocals": true, 21 | "noUnusedParameters": true, 22 | "resolveJsonModule": true, 23 | "skipLibCheck": true, 24 | "strict": true, 25 | "target": "esnext", 26 | "verbatimModuleSyntax": true 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /turbo.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://turbo.build/schema.json", 3 | "pipeline": { 4 | "build:android": { 5 | "inputs": [ 6 | "package.json", 7 | "android", 8 | "!android/build", 9 | "src/*.ts", 10 | "src/*.tsx", 11 | "example/package.json", 12 | "example/android", 13 | "!example/android/.gradle", 14 | "!example/android/build", 15 | "!example/android/app/build" 16 | ], 17 | "outputs": [] 18 | }, 19 | "build:ios": { 20 | "inputs": [ 21 | "package.json", 22 | "*.podspec", 23 | "ios", 24 | "src/*.ts", 25 | "src/*.tsx", 26 | "example/package.json", 27 | "example/ios", 28 | "!example/ios/build", 29 | "!example/ios/Pods" 30 | ], 31 | "outputs": [] 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /example/ios/FastTrieExampleTests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | 24 | 25 | -------------------------------------------------------------------------------- /ios/FastTrie.mm: -------------------------------------------------------------------------------- 1 | #import "FastTrie.h" 2 | 3 | #import 4 | #import 5 | #import 6 | #import "../cpp/fast-trie.h" 7 | 8 | @implementation FastTrie 9 | RCT_EXPORT_MODULE(FastTrie) 10 | 11 | RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(install) { 12 | NSLog(@"Initializing FastTrie module..."); 13 | 14 | RCTBridge *bridge = [RCTBridge currentBridge]; 15 | RCTCxxBridge *cxxBridge = (RCTCxxBridge *)bridge; 16 | if (cxxBridge == nil) { 17 | return @false; 18 | } 19 | 20 | using namespace facebook; 21 | 22 | auto jsiRuntime = (jsi::Runtime *)cxxBridge.runtime; 23 | if (jsiRuntime == nil) { 24 | return @false; 25 | } 26 | auto &runtime = *jsiRuntime; 27 | 28 | fasttrie::install(runtime); 29 | 30 | NSLog(@"FastTrie initialized"); 31 | return @true; 32 | } 33 | 34 | 35 | @end 36 | -------------------------------------------------------------------------------- /example/ios/FastUrlExample/AppDelegate.mm: -------------------------------------------------------------------------------- 1 | #import "AppDelegate.h" 2 | 3 | #import 4 | 5 | @implementation AppDelegate 6 | 7 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 8 | { 9 | self.moduleName = @"FastTrieExample"; 10 | // You can add your custom initial props in the dictionary below. 11 | // They will be passed down to the ViewController used by React Native. 12 | self.initialProps = @{}; 13 | 14 | return [super application:application didFinishLaunchingWithOptions:launchOptions]; 15 | } 16 | 17 | - (NSURL *)sourceURLForBridge:(RCTBridge *)bridge 18 | { 19 | #if DEBUG 20 | return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index"]; 21 | #else 22 | return [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"]; 23 | #endif 24 | } 25 | 26 | @end 27 | -------------------------------------------------------------------------------- /example/src/screens/Benchmarks/benchmarks/find.ts: -------------------------------------------------------------------------------- 1 | import { wordlistEN } from '../../../wordlists/allWordlists'; 2 | import { 3 | type BenchmarkResult, 4 | createTrie, 5 | runBenchmark, 6 | getRandomWordSubstrings, 7 | getFastTrie, 8 | getJsTrie, 9 | } from './utils'; 10 | 11 | function findBench(wordlist: string[]): BenchmarkResult { 12 | const words = getRandomWordSubstrings(wordlist, 10000); 13 | const trie = createTrie(getJsTrie, wordlist); 14 | const fastTrie = createTrie(getFastTrie, wordlist); 15 | 16 | return runBenchmark( 17 | 'Find', 18 | () => { 19 | for (const word of words) { 20 | trie.find(word); 21 | } 22 | }, 23 | () => { 24 | for (const word of words) { 25 | fastTrie.find(word); 26 | } 27 | } 28 | ); 29 | } 30 | 31 | export function registerBenchmarks() { 32 | return [findBench(wordlistEN)]; 33 | } 34 | -------------------------------------------------------------------------------- /cpp/fast-trie.cpp: -------------------------------------------------------------------------------- 1 | #include "fast-trie.h" 2 | 3 | #include "TrieHostObject.h" 4 | 5 | namespace fasttrie { 6 | namespace jsi = facebook::jsi; 7 | 8 | void install(jsi::Runtime &rt) { 9 | auto FastTrie = HOST_FN(rt, "FastTrie", 2, { 10 | if (count != 2 || !arguments[0].isNumber() || !arguments[1].isNumber()) { 11 | throw jsi::JSError(rt, "FastTrie expects two number arguments"); 12 | } 13 | size_t burst_threshold = arguments[0].asNumber(); 14 | size_t max_load_factor = arguments[1].asNumber(); 15 | 16 | return jsi::Object::createFromHostObject( 17 | rt, std::make_shared( 18 | TrieHostObject(burst_threshold, max_load_factor))); 19 | }); 20 | 21 | rt.global().setProperty(rt, "__FastTrie", std::move(FastTrie)); 22 | } 23 | } // namespace fasttrie 24 | -------------------------------------------------------------------------------- /example/src/screens/Benchmarks/benchmarks/contains.ts: -------------------------------------------------------------------------------- 1 | import { wordlistEN } from '../../../wordlists/allWordlists'; 2 | import { 3 | getRandomWords, 4 | type BenchmarkResult, 5 | createTrie, 6 | runBenchmark, 7 | getFastTrie, 8 | getJsTrie, 9 | } from './utils'; 10 | 11 | function containsBench(wordlist: string[]): BenchmarkResult { 12 | const words = getRandomWords(wordlist, 1000000); 13 | const trie = createTrie(getJsTrie, wordlist); 14 | const fastTrie = createTrie(getFastTrie, wordlist); 15 | 16 | return runBenchmark( 17 | 'Contains', 18 | () => { 19 | for (const word of words) { 20 | trie.contains(word); 21 | } 22 | }, 23 | () => { 24 | for (const word of words) { 25 | fastTrie.contains(word); 26 | } 27 | } 28 | ); 29 | } 30 | 31 | export function registerBenchmarks() { 32 | return [containsBench(wordlistEN)]; 33 | } 34 | -------------------------------------------------------------------------------- /example/src/components/CorrectResultItem.tsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import { View, StyleSheet } from 'react-native'; 3 | import { Text } from './Text'; 4 | 5 | type CorrectResultItemProps = { 6 | description: string; 7 | }; 8 | 9 | export const CorrectResultItem: React.FC = ({ 10 | description, 11 | }: CorrectResultItemProps) => { 12 | const emoji = '✅'; 13 | const fullText = emoji + ' [' + description + ']'; 14 | 15 | return ( 16 | 17 | {fullText} 18 | 19 | ); 20 | }; 21 | 22 | const styles = StyleSheet.create({ 23 | scroll: { 24 | flex: 1, 25 | }, 26 | itemContainer: { 27 | borderWidth: 1, 28 | margin: 10, 29 | marginBottom: 5, 30 | flexDirection: 'column', 31 | borderRadius: 5, 32 | padding: 5, 33 | }, 34 | text: { 35 | flexShrink: 1, 36 | }, 37 | }); 38 | -------------------------------------------------------------------------------- /android/src/main/java/com/fasturl/FastTriePackage.java: -------------------------------------------------------------------------------- 1 | package com.fasttrie; 2 | 3 | import androidx.annotation.NonNull; 4 | 5 | import com.facebook.react.ReactPackage; 6 | import com.facebook.react.bridge.NativeModule; 7 | import com.facebook.react.bridge.ReactApplicationContext; 8 | import com.facebook.react.uimanager.ViewManager; 9 | 10 | import java.util.ArrayList; 11 | import java.util.Collections; 12 | import java.util.List; 13 | 14 | public class FastTriePackage implements ReactPackage { 15 | @NonNull 16 | @Override 17 | public List createNativeModules(@NonNull ReactApplicationContext reactContext) { 18 | List modules = new ArrayList<>(); 19 | modules.add(new FastTrieModule(reactContext)); 20 | return modules; 21 | } 22 | 23 | @NonNull 24 | @Override 25 | public List createViewManagers(@NonNull ReactApplicationContext reactContext) { 26 | return Collections.emptyList(); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /android/cpp-adapter.cpp: -------------------------------------------------------------------------------- 1 | #include "fast-trie.h" 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | using namespace facebook; 8 | 9 | struct FastTrieBridge : jni::JavaClass { 10 | static constexpr auto kJavaDescriptor = 11 | "Lcom/fasttrie/FastTrieBridge;"; 12 | 13 | static void registerNatives() { 14 | javaClassStatic()->registerNatives( 15 | {// initialization for JSI 16 | makeNativeMethod("installNativeJsi", 17 | FastTrieBridge::installNativeJsi) 18 | }); 19 | } 20 | 21 | private: 22 | static void installNativeJsi( 23 | jni::alias_ref thiz, jlong jsiRuntimePtr) { 24 | auto jsiRuntime = reinterpret_cast(jsiRuntimePtr); 25 | 26 | fasttrie::install(*jsiRuntime); 27 | } 28 | }; 29 | 30 | JNIEXPORT jint JNI_OnLoad(JavaVM *vm, void *) { 31 | return jni::initialize(vm, [] { FastTrieBridge::registerNatives(); }); 32 | } 33 | -------------------------------------------------------------------------------- /example/src/components/IncorrectResultItem.tsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import { View, StyleSheet } from 'react-native'; 3 | import { Text } from './Text'; 4 | 5 | type IncorrectResultItemProps = { 6 | description: string; 7 | errorMsg: string; 8 | }; 9 | 10 | export const IncorrectResultItem: React.FC = ({ 11 | description, 12 | errorMsg, 13 | }: IncorrectResultItemProps) => { 14 | const emoji = '❌'; 15 | const fullText = emoji + ' [' + description + '] ---> ' + errorMsg; 16 | 17 | return ( 18 | 19 | {fullText} 20 | 21 | ); 22 | }; 23 | 24 | const styles = StyleSheet.create({ 25 | scroll: { 26 | flex: 1, 27 | }, 28 | itemContainer: { 29 | borderWidth: 1, 30 | margin: 10, 31 | marginBottom: 5, 32 | flexDirection: 'column', 33 | borderRadius: 5, 34 | padding: 5, 35 | }, 36 | text: { 37 | flexShrink: 1, 38 | }, 39 | }); 40 | -------------------------------------------------------------------------------- /example/src/screens/Tests/testList.tsx: -------------------------------------------------------------------------------- 1 | import { registerConfigurationAndErrorHandlingTests } from './tests/configurationAndErrorHandlingTests'; 2 | import { registerDeletionTests } from './tests/deletionTests'; 3 | import { registerFindAndContainsTests } from './tests/findAndContainsTests'; 4 | import { registerInsertionTests } from './tests/insertionTests'; 5 | import { type TestItemType } from './types'; 6 | 7 | export const TEST_LIST: Array = [ 8 | { 9 | description: 'Insertion tests', 10 | value: true, 11 | registrator: registerInsertionTests, 12 | }, 13 | { 14 | description: 'Deletion tests', 15 | value: true, 16 | registrator: registerDeletionTests, 17 | }, 18 | { 19 | description: 'Find and Contains tests', 20 | value: true, 21 | registrator: registerFindAndContainsTests, 22 | }, 23 | { 24 | description: 'Configuration and Error Handling', 25 | value: true, 26 | registrator: registerConfigurationAndErrorHandlingTests, 27 | }, 28 | ]; 29 | -------------------------------------------------------------------------------- /example/src/components/NavigationButton.tsx: -------------------------------------------------------------------------------- 1 | import * as React from 'react'; 2 | import { Pressable, StyleSheet, Text } from 'react-native'; 3 | 4 | type Props = { 5 | onPress: () => void; 6 | title: string; 7 | }; 8 | 9 | export function NavigationButton({ onPress, title }: Props) { 10 | return ( 11 | [ 14 | { 15 | backgroundColor: pressed ? 'rgb(210, 230, 255)' : 'white', 16 | }, 17 | styles.wrapperCustom, 18 | ]} 19 | > 20 | {title} 21 | 22 | ); 23 | } 24 | 25 | const styles = StyleSheet.create({ 26 | container: { 27 | flex: 1, 28 | justifyContent: 'center', 29 | }, 30 | text: { 31 | minWidth: 150, 32 | textAlign: 'center', 33 | fontSize: 18, 34 | color: 'black', 35 | }, 36 | wrapperCustom: { 37 | borderWidth: 1, 38 | borderColor: 'black', 39 | borderRadius: 8, 40 | padding: 8, 41 | marginBottom: 12, 42 | }, 43 | }); 44 | -------------------------------------------------------------------------------- /scripts/pod-install.cjs: -------------------------------------------------------------------------------- 1 | const child_process = require('child_process'); 2 | 3 | module.exports = { 4 | name: 'pod-install', 5 | factory() { 6 | return { 7 | hooks: { 8 | afterAllInstalled(project, options) { 9 | if (process.env.POD_INSTALL === '0') { 10 | return; 11 | } 12 | 13 | if ( 14 | options && 15 | (options.mode === 'update-lockfile' || 16 | options.mode === 'skip-build') 17 | ) { 18 | return; 19 | } 20 | 21 | const result = child_process.spawnSync( 22 | 'yarn', 23 | ['pod-install', 'example/ios'], 24 | { 25 | cwd: project.cwd, 26 | env: process.env, 27 | stdio: 'inherit', 28 | encoding: 'utf-8', 29 | shell: true, 30 | } 31 | ); 32 | 33 | if (result.status !== 0) { 34 | throw new Error('Failed to run pod-install'); 35 | } 36 | }, 37 | }, 38 | }; 39 | }, 40 | }; 41 | -------------------------------------------------------------------------------- /example/src/testing/MochaRnAdapter.ts: -------------------------------------------------------------------------------- 1 | import 'mocha'; 2 | import type * as MochaTypes from 'mocha'; 3 | 4 | export const rootSuite = new Mocha.Suite('') as MochaTypes.Suite; 5 | 6 | let mochaContext = rootSuite; 7 | let only = false; 8 | 9 | export const clearTests = () => { 10 | rootSuite.suites = []; 11 | rootSuite.tests = []; 12 | mochaContext = rootSuite; 13 | only = false; 14 | }; 15 | 16 | export const it = (name: string, f: () => void): void => { 17 | if (!only) { 18 | mochaContext.addTest(new Mocha.Test(name, f) as MochaTypes.Test); 19 | } 20 | }; 21 | 22 | export const itOnly = (name: string, f: () => void): void => { 23 | clearTests(); 24 | mochaContext.addTest(new Mocha.Test(name, f) as MochaTypes.Test); 25 | only = true; 26 | }; 27 | 28 | export const describe = (name: string, f: () => void): void => { 29 | const prevMochaContext = mochaContext; 30 | mochaContext = new Mocha.Suite( 31 | name, 32 | prevMochaContext.ctx 33 | ) as MochaTypes.Suite; 34 | prevMochaContext.addSuite(mochaContext); 35 | f(); 36 | mochaContext = prevMochaContext; 37 | }; 38 | -------------------------------------------------------------------------------- /example/android/app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 12 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # OSX 2 | # 3 | .DS_Store 4 | 5 | # XDE 6 | .expo/ 7 | 8 | # VSCode 9 | .vscode/ 10 | jsconfig.json 11 | 12 | # Xcode 13 | # 14 | build/ 15 | *.pbxuser 16 | !default.pbxuser 17 | *.mode1v3 18 | !default.mode1v3 19 | *.mode2v3 20 | !default.mode2v3 21 | *.perspectivev3 22 | !default.perspectivev3 23 | xcuserdata 24 | *.xccheckout 25 | *.moved-aside 26 | DerivedData 27 | *.hmap 28 | *.ipa 29 | *.xcuserstate 30 | project.xcworkspace 31 | 32 | # Android/IJ 33 | # 34 | .classpath 35 | .cxx 36 | .gradle 37 | .idea 38 | .project 39 | .settings 40 | local.properties 41 | android.iml 42 | 43 | # Cocoapods 44 | # 45 | example/ios/Pods 46 | 47 | # Ruby 48 | example/vendor/ 49 | 50 | # node.js 51 | # 52 | node_modules/ 53 | npm-debug.log 54 | yarn-debug.log 55 | yarn-error.log 56 | 57 | # BUCK 58 | buck-out/ 59 | \.buckd/ 60 | android/app/libs 61 | android/keystores/debug.keystore 62 | 63 | # Yarn 64 | .yarn/* 65 | !.yarn/patches 66 | !.yarn/plugins 67 | !.yarn/releases 68 | !.yarn/sdks 69 | !.yarn/versions 70 | 71 | # Expo 72 | .expo/ 73 | 74 | # Turborepo 75 | .turbo/ 76 | 77 | # generated by bob 78 | lib/ 79 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 kusstar 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | SOFTWARE. 21 | -------------------------------------------------------------------------------- /example/ios/FastUrlExample/Images.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "scale" : "2x", 6 | "size" : "20x20" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "scale" : "3x", 11 | "size" : "20x20" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "scale" : "2x", 16 | "size" : "29x29" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "scale" : "3x", 21 | "size" : "29x29" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "scale" : "2x", 26 | "size" : "40x40" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "scale" : "3x", 31 | "size" : "40x40" 32 | }, 33 | { 34 | "idiom" : "iphone", 35 | "scale" : "2x", 36 | "size" : "60x60" 37 | }, 38 | { 39 | "idiom" : "iphone", 40 | "scale" : "3x", 41 | "size" : "60x60" 42 | }, 43 | { 44 | "idiom" : "ios-marketing", 45 | "scale" : "1x", 46 | "size" : "1024x1024" 47 | } 48 | ], 49 | "info" : { 50 | "author" : "xcode", 51 | "version" : 1 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /example/src/components/TestItem.tsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import { View, StyleSheet } from 'react-native'; 3 | import Checkbox from '@react-native-community/checkbox'; 4 | import { Text } from './Text'; 5 | 6 | type TestItemProps = { 7 | description: string; 8 | value: boolean; 9 | index: number; 10 | onToggle: (index: number) => void; 11 | }; 12 | 13 | export const TestItem: React.FC = ({ 14 | description, 15 | value, 16 | index, 17 | onToggle, 18 | }: TestItemProps) => { 19 | return ( 20 | 21 | {description} 22 | { 25 | onToggle(index); 26 | }} 27 | /> 28 | 29 | ); 30 | }; 31 | 32 | const styles = StyleSheet.create({ 33 | container: { 34 | borderRadius: 6, 35 | width: '100%', 36 | padding: 10, 37 | paddingHorizontal: 25, 38 | flexDirection: 'row', 39 | alignContent: 'center', 40 | alignItems: 'center', 41 | justifyContent: 'space-between', 42 | backgroundColor: '#d1e8ff', 43 | marginTop: 10, 44 | }, 45 | }); 46 | -------------------------------------------------------------------------------- /example/src/App.tsx: -------------------------------------------------------------------------------- 1 | import * as React from 'react'; 2 | import { NavigationContainer } from '@react-navigation/native'; 3 | import { createNativeStackNavigator } from '@react-navigation/native-stack'; 4 | 5 | import { Home } from './screens/Home'; 6 | import { Benchmarks } from './screens/Benchmarks/Benchmarks'; 7 | import { Tests } from './screens/Tests/Tests'; 8 | import type { RootStackParamList } from './screens/params'; 9 | import { SpeedBenchmarks } from './screens/Benchmarks/SpeedBenchmarks'; 10 | import { MemoryBenchmarks } from './screens/Benchmarks/MemoryBenchmarks'; 11 | 12 | const Stack = createNativeStackNavigator(); 13 | 14 | export default function App() { 15 | return ( 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | ); 26 | } 27 | -------------------------------------------------------------------------------- /example/src/screens/Tests/tests/configurationAndErrorHandlingTests.ts: -------------------------------------------------------------------------------- 1 | import { describe, it } from '../../../testing/MochaRnAdapter'; 2 | import { expect } from 'chai'; 3 | import { FastTrie } from 'react-native-fast-trie'; 4 | 5 | export function registerConfigurationAndErrorHandlingTests() { 6 | describe('FastTrie Configuration and Error Handling Tests', () => { 7 | it('should not crash with valid burstThreshold and maxLoadFactor values', () => { 8 | expect( 9 | () => new FastTrie({ burstThreshold: 1024, maxLoadFactor: 8.0 }) 10 | ).to.not.throw(); 11 | expect( 12 | () => new FastTrie({ burstThreshold: 2048, maxLoadFactor: 10.0 }) 13 | ).to.not.throw(); 14 | }); 15 | 16 | it('should throw an error when instantiated with an invalid type for burstThreshold', () => { 17 | expect( 18 | () => new FastTrie({ burstThreshold: 'invalid' as unknown as number }) 19 | ).to.throw(); 20 | }); 21 | 22 | it('should throw an error when instantiated with an invalid type for maxLoadFactor', () => { 23 | expect( 24 | () => new FastTrie({ maxLoadFactor: 'invalid' as unknown as number }) 25 | ).to.throw(); 26 | }); 27 | }); 28 | } 29 | -------------------------------------------------------------------------------- /android/src/main/java/com/fasturl/FastTrieModule.java: -------------------------------------------------------------------------------- 1 | package com.fasttrie; 2 | 3 | import androidx.annotation.NonNull; 4 | import android.util.Log; 5 | 6 | import com.facebook.react.bridge.Promise; 7 | import com.facebook.react.bridge.ReactApplicationContext; 8 | import com.facebook.react.bridge.ReactContextBaseJavaModule; 9 | import com.facebook.react.bridge.ReactMethod; 10 | import com.facebook.react.module.annotations.ReactModule; 11 | 12 | @ReactModule(name = FastTrieModule.NAME) 13 | public class FastTrieModule extends ReactContextBaseJavaModule { 14 | public static final String NAME = "FastTrie"; 15 | 16 | public FastTrieModule(ReactApplicationContext reactContext) { 17 | super(reactContext); 18 | } 19 | 20 | @Override 21 | @NonNull 22 | public String getName() { 23 | return NAME; 24 | } 25 | 26 | @ReactMethod(isBlockingSynchronousMethod = true) 27 | public boolean install() { 28 | try { 29 | System.loadLibrary("fast-trie"); 30 | FastTrieBridge.instance.install(getReactApplicationContext()); 31 | return true; 32 | } catch (Exception exception) { 33 | Log.e(NAME, "Failed to install JSI Bindings!", exception); 34 | return false; 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /example/src/screens/Benchmarks/Benchmarks.tsx: -------------------------------------------------------------------------------- 1 | import * as React from 'react'; 2 | 3 | import { StyleSheet, View } from 'react-native'; 4 | import { Button } from '../../components/Button'; 5 | import { useNavigation } from '@react-navigation/native'; 6 | import type { NativeStackNavigationProp } from '@react-navigation/native-stack'; 7 | import type { RootStackParamList } from '../params'; 8 | 9 | export function Benchmarks() { 10 | const navigation = 11 | useNavigation>(); 12 | 13 | return ( 14 | 15 |