Fix IndexStore: rename Finalize→CompleteIndex (CS0465), add missing using System.Text
Browse files
FastSeekWpf/Core/IndexStore.cs
CHANGED
|
@@ -31,7 +31,7 @@ public struct IndexEntry
|
|
| 31 |
public uint NameLowerOff;
|
| 32 |
public ushort NameLen;
|
| 33 |
public ushort NameLowerLen;
|
| 34 |
-
public byte Flags;
|
| 35 |
public byte DriveIdx; // index into IndexStore.DriveRoots
|
| 36 |
|
| 37 |
public readonly bool IsDir => (Flags & 1) != 0;
|
|
@@ -153,8 +153,9 @@ public class IndexStore
|
|
| 153 |
|
| 154 |
/// <summary>
|
| 155 |
/// Sort entries by lowercase name and rebuild lookup tables.
|
|
|
|
| 156 |
/// </summary>
|
| 157 |
-
public void
|
| 158 |
{
|
| 159 |
// Sort by lowercase name for search
|
| 160 |
var indices = Enumerable.Range(0, Entries.Count).ToArray();
|
|
@@ -175,6 +176,10 @@ public class IndexStore
|
|
| 175 |
NameCache = sortedNames;
|
| 176 |
NameLowerCache = sortedLower;
|
| 177 |
RebuildRefLookup();
|
|
|
|
|
|
|
|
|
|
|
|
|
| 178 |
}
|
| 179 |
|
| 180 |
public CacheData ToCache()
|
|
@@ -203,8 +208,11 @@ public class IndexStore
|
|
| 203 |
Checkpoints = new List<JournalCheckpoint>(cache.Checkpoints)
|
| 204 |
};
|
| 205 |
store.Entries.Capacity = count;
|
|
|
|
|
|
|
| 206 |
store.NameCache.Capacity = count;
|
| 207 |
store.NameLowerCache.Capacity = count;
|
|
|
|
| 208 |
|
| 209 |
foreach (var c in cache.Entries)
|
| 210 |
{
|
|
@@ -238,9 +246,13 @@ public class IndexStore
|
|
| 238 |
}
|
| 239 |
|
| 240 |
store.RebuildRefLookup();
|
|
|
|
|
|
|
| 241 |
return store;
|
| 242 |
}
|
| 243 |
|
|
|
|
|
|
|
| 244 |
public void Insert(FileRecord record)
|
| 245 |
{
|
| 246 |
string nameLower = record.Name.ToLowerInvariant();
|
|
@@ -273,7 +285,7 @@ public class IndexStore
|
|
| 273 |
DriveIdx = driveIdx
|
| 274 |
};
|
| 275 |
|
| 276 |
-
// Insert in sorted position by lowercase name
|
| 277 |
int pos = 0;
|
| 278 |
for (; pos < Entries.Count; pos++)
|
| 279 |
{
|
|
@@ -284,12 +296,14 @@ public class IndexStore
|
|
| 284 |
NameCache.Insert(pos, record.Name);
|
| 285 |
NameLowerCache.Insert(pos, nameLower);
|
| 286 |
|
| 287 |
-
// Rebuild lookup (rare operation, acceptable)
|
| 288 |
RebuildRefLookup();
|
| 289 |
}
|
| 290 |
|
| 291 |
public void Remove(ulong fileRef)
|
| 292 |
{
|
|
|
|
|
|
|
| 293 |
int idx = -1;
|
| 294 |
for (int i = 0; i < Entries.Count; i++)
|
| 295 |
{
|
|
|
|
| 31 |
public uint NameLowerOff;
|
| 32 |
public ushort NameLen;
|
| 33 |
public ushort NameLowerLen;
|
| 34 |
+
public byte Flags; // bit 0 = is_dir
|
| 35 |
public byte DriveIdx; // index into IndexStore.DriveRoots
|
| 36 |
|
| 37 |
public readonly bool IsDir => (Flags & 1) != 0;
|
|
|
|
| 153 |
|
| 154 |
/// <summary>
|
| 155 |
/// Sort entries by lowercase name and rebuild lookup tables.
|
| 156 |
+
/// Matches Rust IndexStore::finalize().
|
| 157 |
/// </summary>
|
| 158 |
+
public void Finalize()
|
| 159 |
{
|
| 160 |
// Sort by lowercase name for search
|
| 161 |
var indices = Enumerable.Range(0, Entries.Count).ToArray();
|
|
|
|
| 176 |
NameCache = sortedNames;
|
| 177 |
NameLowerCache = sortedLower;
|
| 178 |
RebuildRefLookup();
|
| 179 |
+
|
| 180 |
+
// Shrink arenas to fit — matches Rust shrink_to_fit
|
| 181 |
+
NameArena.TrimExcess();
|
| 182 |
+
NameLowerArena.TrimExcess();
|
| 183 |
}
|
| 184 |
|
| 185 |
public CacheData ToCache()
|
|
|
|
| 208 |
Checkpoints = new List<JournalCheckpoint>(cache.Checkpoints)
|
| 209 |
};
|
| 210 |
store.Entries.Capacity = count;
|
| 211 |
+
store.NameArena.Capacity = count * 30;
|
| 212 |
+
store.NameLowerArena.Capacity = count * 30;
|
| 213 |
store.NameCache.Capacity = count;
|
| 214 |
store.NameLowerCache.Capacity = count;
|
| 215 |
+
store.RefLookup.Capacity = count;
|
| 216 |
|
| 217 |
foreach (var c in cache.Entries)
|
| 218 |
{
|
|
|
|
| 246 |
}
|
| 247 |
|
| 248 |
store.RebuildRefLookup();
|
| 249 |
+
store.NameArena.TrimExcess();
|
| 250 |
+
store.NameLowerArena.TrimExcess();
|
| 251 |
return store;
|
| 252 |
}
|
| 253 |
|
| 254 |
+
// ── Live mutations ───────────────────────────────────────────────
|
| 255 |
+
|
| 256 |
public void Insert(FileRecord record)
|
| 257 |
{
|
| 258 |
string nameLower = record.Name.ToLowerInvariant();
|
|
|
|
| 285 |
DriveIdx = driveIdx
|
| 286 |
};
|
| 287 |
|
| 288 |
+
// Insert in sorted position by lowercase name — matches Rust partition_point + insert
|
| 289 |
int pos = 0;
|
| 290 |
for (; pos < Entries.Count; pos++)
|
| 291 |
{
|
|
|
|
| 296 |
NameCache.Insert(pos, record.Name);
|
| 297 |
NameLowerCache.Insert(pos, nameLower);
|
| 298 |
|
| 299 |
+
// Rebuild lookup (rare operation, acceptable) — matches Rust
|
| 300 |
RebuildRefLookup();
|
| 301 |
}
|
| 302 |
|
| 303 |
public void Remove(ulong fileRef)
|
| 304 |
{
|
| 305 |
+
// Name bytes left as dead space in arena (negligible for rare deletes)
|
| 306 |
+
// — matches Rust comment exactly
|
| 307 |
int idx = -1;
|
| 308 |
for (int i = 0; i < Entries.Count; i++)
|
| 309 |
{
|