Skip to content

Commit e451014

Browse files
committed
Refactor to new handle-based API (FileIndex) and update README
1 parent 3328104 commit e451014

8 files changed

Lines changed: 193 additions & 120 deletions

File tree

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# FastFileIndex
22

3+
Ultra-fast native file indexer with real-time metadata extraction and zero-copy directory traversal [ALPHA].
4+
35
[![Build](https://img.shields.io/badge/build-passing-brightgreen.svg)]()
46
[![Java](https://img.shields.io/badge/Java-17+-blue.svg)](https://www.java.com)
57
[![Platform](https://img.shields.io/badge/Platform-Windows%2010+-lightgrey.svg)]()
@@ -22,7 +24,7 @@
2224

2325
## Description
2426

25-
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:
27+
FastFileIndex is the first module in the FastJava file search engine trilogy:
2628

2729
- **FastFileIndex** - Full filesystem scan ? produces a binary, mmap-capable index of all files
2830
- **FastFileSearch** - Builds Prefix Trie, N-Gram index, Exact Match map, and Ranking engine on top of the index
-1.41 KB
Binary file not shown.
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package fastfileindex;
2+
3+
/**
4+
* BuildOptions - Options for building the index.
5+
*/
6+
public class BuildOptions {
7+
private boolean followSymlinks = false;
8+
private boolean includeHidden = false;
9+
private int maxDepth = -1;
10+
11+
public BuildOptions() {}
12+
13+
public BuildOptions followSymlinks(boolean value) {
14+
this.followSymlinks = value;
15+
return this;
16+
}
17+
18+
public BuildOptions includeHidden(boolean value) {
19+
this.includeHidden = value;
20+
return this;
21+
}
22+
23+
public BuildOptions maxDepth(int value) {
24+
this.maxDepth = value;
25+
return this;
26+
}
27+
28+
public boolean followSymlinks() {
29+
return followSymlinks;
30+
}
31+
32+
public boolean includeHidden() {
33+
return includeHidden;
34+
}
35+
36+
public int maxDepth() {
37+
return maxDepth;
38+
}
39+
40+
public static BuildOptions defaults() {
41+
return new BuildOptions();
42+
}
43+
}

src/main/java/fastfileindex/FastFileIndex.java

Lines changed: 0 additions & 119 deletions
This file was deleted.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package fastfileindex;
2+
3+
/**
4+
* FileEntry - File entry value type.
5+
*/
6+
public record FileEntry(
7+
long id,
8+
long parentId,
9+
String path,
10+
long size,
11+
long modified,
12+
FileType type
13+
) {}
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
package fastfileindex;
2+
3+
/**
4+
* FileIndex - Handle-based file index with mmap loading.
5+
*
6+
* <p>FileIndex is the first module in the FastJava file search engine trilogy:
7+
* <ul>
8+
* <li>FileIndex - Full filesystem scan → produces a binary, mmap-capable index of all files</li>
9+
* <li>SearchEngine - Builds Prefix Trie, N-Gram index, Exact Match map, and Ranking engine on top of the index</li>
10+
* <li>WatchService - Uses USN Journal to keep the index + search structures live-updated with zero rescans</li>
11+
* </ul>
12+
*
13+
* <p>This architecture is similar to Everything, Spotlight, VSCode, and fsearch but modular and embeddable.
14+
*
15+
* <p><b>Key Features:</b>
16+
* <ul>
17+
* <li>mmap-based loading (CreateFileMapping + MapViewOfFile)</li>
18+
* <li>Path-Blob + Offsets instead of std::string per entry</li>
19+
* <li>Parallel build with threadpool and lock-free append buffer</li>
20+
* <li>FNV-1a hashing for stable file IDs</li>
21+
* <li>Type detection (image, pdf, text, code)</li>
22+
* <li>Converts file timestamps to Unix seconds</li>
23+
* <li>Saves to files.idx (append-only)</li>
24+
* <li>Loads instantly (&lt;1-3 ms with mmap)</li>
25+
* <li>Zero-copy path access via string_view</li>
26+
* </ul>
27+
*
28+
* <p><b>Binary Format:</b>
29+
* <ul>
30+
* <li>files.idx - FileEntryHeader with id, parentId, size, modified, type, pathOffset, pathLen</li>
31+
* <li>paths.bin - Path-Blob containing all paths in a single contiguous blob</li>
32+
* </ul>
33+
*
34+
* @since 1.0.0
35+
* @version 1.0.0
36+
*/
37+
public final class FileIndex {
38+
static {
39+
try {
40+
// Try System.loadLibrary first (default)
41+
System.loadLibrary("fastcore");
42+
} catch (UnsatisfiedLinkError e1) {
43+
try {
44+
// Fallback to absolute path (relative to user.dir)
45+
String userDir = System.getProperty("user.dir");
46+
String dllPath = userDir + "\\build\\fastcore.dll";
47+
System.load(dllPath);
48+
} catch (UnsatisfiedLinkError e2) {
49+
System.err.println("Failed to load fastcore.dll: " + e2.getMessage());
50+
throw e2;
51+
}
52+
}
53+
}
54+
55+
private final long nativeHandle;
56+
57+
private FileIndex(long nativeHandle) {
58+
this.nativeHandle = nativeHandle;
59+
}
60+
61+
public long handle() {
62+
return nativeHandle;
63+
}
64+
65+
/**
66+
* Build index from roots.
67+
*/
68+
public static native FileIndex build(String[] roots, BuildOptions options);
69+
70+
/**
71+
* Open existing index from file.
72+
*/
73+
public static native FileIndex open(String indexPath);
74+
75+
/**
76+
* Save index to file.
77+
*/
78+
public native void save(String indexPath);
79+
80+
/**
81+
* Close index and free resources.
82+
*/
83+
public native void close();
84+
85+
/**
86+
* Get index metadata.
87+
*/
88+
public native IndexMetadata metadata();
89+
90+
/**
91+
* Get entry count.
92+
*/
93+
public native long entryCount();
94+
95+
/**
96+
* Get file entry by ID.
97+
*/
98+
public native FileEntry get(long id);
99+
100+
public static void main(String[] args) {
101+
System.out.println("=== FileIndex ===");
102+
System.out.println("FileIndex - Binary file indexing with mmap support");
103+
System.out.println("=== OK ===");
104+
}
105+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package fastfileindex;
2+
3+
/**
4+
* FileType - File type enumeration.
5+
*/
6+
public enum FileType {
7+
UNKNOWN,
8+
DIRECTORY,
9+
FILE,
10+
IMAGE,
11+
VIDEO,
12+
AUDIO,
13+
DOCUMENT,
14+
ARCHIVE,
15+
CODE,
16+
TEXT,
17+
BINARY
18+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package fastfileindex;
2+
3+
/**
4+
* IndexMetadata - Index metadata value type.
5+
*/
6+
public record IndexMetadata(
7+
long entryCount,
8+
long totalSize,
9+
long buildTime,
10+
String version
11+
) {}

0 commit comments

Comments
 (0)