|
| 1 | +# FastFileIndex |
| 2 | + |
| 3 | +[]() |
| 4 | +[](https://www.java.com) |
| 5 | +[]() |
| 6 | +[](https://opensource.org/licenses/MIT) |
| 7 | +[](https://jitpack.io/#andrestubbe/FastFileIndex) |
| 8 | + |
| 9 | +## Table of Contents |
| 10 | + |
| 11 | +- [Description](#description) |
| 12 | +- [Quick Start](#quick-start) |
| 13 | +- [Key Features](#key-features) |
| 14 | +- [Installation](#installation) |
| 15 | +- [Building from Source](#building-from-source) |
| 16 | +- [Platform Support](#platform-support) |
| 17 | +- [License](#license) |
| 18 | +- [Related Projects](#related-projects) |
| 19 | + |
| 20 | +## Description |
| 21 | + |
| 22 | +FastFileIndex creates a compact, append-only, mmap-friendly binary index of all files. It is the first module in the FastJava file search engine trilogy: |
| 23 | + |
| 24 | +- **FastFileIndex** - Full filesystem scan ? produces a binary, mmap-capable index of all files |
| 25 | +- **FastFileSearch** - Builds Prefix Trie, N-Gram index, Exact Match map, and Ranking engine on top of the index |
| 26 | +- **FastFileWatch** - Uses USN Journal to keep the index + search structures live-updated with zero rescans |
| 27 | + |
| 28 | +This architecture is similar to Everything, Spotlight, VSCode, and fsearch but modular and embeddable. |
| 29 | + |
| 30 | +## Quick Start |
| 31 | + |
| 32 | +```java |
| 33 | +import fastfileindex.FastFileIndex; |
| 34 | + |
| 35 | +public class Example { |
| 36 | + public static void main(String[] args) { |
| 37 | + // Build index from root directories |
| 38 | + String[] roots = { "C:\\Users\\YourName\\Documents" }; |
| 39 | + FastFileIndex.build(roots); |
| 40 | + |
| 41 | + // Save to binary file |
| 42 | + FastFileIndex.save("files.idx"); |
| 43 | + |
| 44 | + // Load from binary file (instant with mmap) |
| 45 | + FastFileIndex.load("files.idx"); |
| 46 | + |
| 47 | + // Query entries |
| 48 | + long count = FastFileIndex.getEntryCount(); |
| 49 | + System.out.println("Indexed files: " + count); |
| 50 | + |
| 51 | + // Get file information |
| 52 | + String path = FastFileIndex.getEntryPath(0); |
| 53 | + long size = FastFileIndex.getEntrySize(0); |
| 54 | + long modified = FastFileIndex.getEntryModified(0); |
| 55 | + int type = FastFileIndex.getEntryType(0); |
| 56 | + } |
| 57 | +} |
| 58 | +``` |
| 59 | + |
| 60 | +## Key Features |
| 61 | + |
| 62 | +- **mmap-based loading** - Uses CreateFileMapping + MapViewOfFile for zero-copy access |
| 63 | +- **Path-Blob storage** - All paths stored in a single contiguous blob for better cache behavior |
| 64 | +- **Parallel build** - Threadpool with lock-free append buffer for fast scanning |
| 65 | +- **FNV-1a hashing** - Stable file IDs based on path hash |
| 66 | +- **Type detection** - Automatic detection of images, PDFs, text, code, video, audio, archives |
| 67 | +- **Unix timestamps** - Converts file timestamps to Unix seconds |
| 68 | +- **Append-only format** - No fragmentation, no locks needed |
| 69 | +- **Instant loading** - Loads in <1-3 ms with memory-mapped I/O |
| 70 | +- **Zero-copy access** - Path access via string_view without copying |
| 71 | + |
| 72 | +## Binary Format |
| 73 | + |
| 74 | +The index consists of two files: |
| 75 | + |
| 76 | +- **files.idx** - FileEntryHeader records with id, parentId, size, modified, type, pathOffset, pathLen |
| 77 | +- **paths.bin** - Path-Blob containing all paths in a single contiguous blob |
| 78 | + |
| 79 | +## Installation |
| 80 | + |
| 81 | +### Maven |
| 82 | + |
| 83 | +Add JitPack repository to your `pom.xml`: |
| 84 | + |
| 85 | +```xml |
| 86 | +<repositories> |
| 87 | + <repository> |
| 88 | + <id>jitpack.io</id> |
| 89 | + <url>https://jitpack.io</url> |
| 90 | + </repository> |
| 91 | +</repositories> |
| 92 | +``` |
| 93 | + |
| 94 | +Add dependency: |
| 95 | + |
| 96 | +```xml |
| 97 | +<dependency> |
| 98 | + <groupId>com.github.andrestubbe</groupId> |
| 99 | + <artifactId>fastfileindex</artifactId> |
| 100 | + <version>v1.0.0</version> |
| 101 | +</dependency> |
| 102 | +``` |
| 103 | + |
| 104 | +### Gradle |
| 105 | + |
| 106 | +Add JitPack repository: |
| 107 | + |
| 108 | +```groovy |
| 109 | +repositories { |
| 110 | + maven { url 'https://jitpack.io' } |
| 111 | +} |
| 112 | +``` |
| 113 | + |
| 114 | +Add dependency: |
| 115 | + |
| 116 | +```groovy |
| 117 | +implementation 'com.github.andrestubbe:fastfileindex:v1.0.0' |
| 118 | +version>' |
| 119 | +``` |
| 120 | + |
| 121 | +## Building from Source |
| 122 | + |
| 123 | +### Requirements |
| 124 | + |
| 125 | +- Java JDK 17+ |
| 126 | +- Visual Studio Build Tools (for C++ compilation on Windows) |
| 127 | +- Maven 3.6+ |
| 128 | + |
| 129 | +### Native Compilation |
| 130 | + |
| 131 | +```bash |
| 132 | +compile.bat |
| 133 | +``` |
| 134 | + |
| 135 | +This script: |
| 136 | +1. Loads Visual Studio Build Tools environment |
| 137 | +2. Compiles C++ source to DLL |
| 138 | +3. Copies DLL to resources directory |
| 139 | + |
| 140 | +### Maven Build |
| 141 | + |
| 142 | +```bash |
| 143 | +mvn clean package |
| 144 | +``` |
| 145 | + |
| 146 | +This creates: |
| 147 | +- `target/fastfileindex-v1.0.0.jar` - Standard JAR |
| 148 | +- `target/fastfileindex-v1.0.0-jar-with-dependencies.jar` - FatJAR with all dependencies and native DLL |
| 149 | + |
| 150 | +### Running |
| 151 | + |
| 152 | +```bash |
| 153 | +java -jar target/fastfileindex-v1.0.0-jar-with-dependencies.jar |
| 154 | +``` |
| 155 | + |
| 156 | +**Note:** When running the demo, ensure you are in the `build` directory for DLL loading: |
| 157 | +```bash |
| 158 | +cd build |
| 159 | +java -cp ..\target\fastfileindex-v1.0.0-jar-with-dependencies.jar;..\examples\Demo\src\main\java fastfileindex.Demo |
| 160 | +``` |
| 161 | + |
| 162 | +## Platform Support |
| 163 | + |
| 164 | +- **Windows 10+** (x86_64) - Fully supported with native implementation |
| 165 | +- **Linux** - Planned |
| 166 | +- **macOS** - Planned |
| 167 | + |
| 168 | +## License |
| 169 | + |
| 170 | +This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details. |
| 171 | + |
| 172 | +## Related Projects |
| 173 | + |
| 174 | +- [FastFileSearch](https://github.com/andrestubbe/FastFileSearch) - Prefix Trie, N-Gram index, and Ranking engine |
| 175 | +- [FastFileWatch](https://github.com/andrestubbe/FastFileWatch) - USN Journal-based live updates |
| 176 | +- [FastCore](https://github.com/andrestubbe/FastCore) - Unified JNI loader and platform abstraction |
0 commit comments