public void Merge(Provider other) { foreach (var kv in other.FullPathToEntry) { var theirs = other.Entries [kv.Value]; int index; if (!FullPathToEntry.TryGetValue(kv.Key, out index)) { FullPathToEntry.Add(kv.Key, CurrentId); Entries.Add(CurrentId, theirs); CurrentId = CurrentId + 1; } else { var ours = Entries [index]; // check to see if we've removed an entry, unless we recently // updated the entry: long maxFreq = Math.Max(theirs.Frequency, ours.Frequency); if (!theirs.IsValid && theirs.LastAccessTime >= ours.LastAccessTime) { maxFreq = Entry.cInvalid; } else if (!ours.IsValid && ours.LastAccessTime >= theirs.LastAccessTime) { maxFreq = Entry.cInvalid; } Entries [index] = new Entry(ours.FullPath, maxFreq, Math.Max(theirs.LastAccessTimeUtc, ours.LastAccessTimeUtc), ours.IsLeaf); } } }
public bool Remove(string fullPath) { var fullPathLower = fullPath.ToLower().TrimEnd(new char[] { '\\', '/' }); int id; if (!FullPathToEntry.TryGetValue(fullPathLower, out id)) { return(false); } return(UpdateEntry(id, remove: true)); }
public bool UpdateEntry(string fullPath, Predicate <string> checkIsLeaf = null) { int id; fullPath = fullPath.TrimEnd(new char[] { '\\', '/' }); string fullPathLower = fullPath.ToLower(); if (!FullPathToEntry.TryGetValue(fullPathLower, out id)) { if (checkIsLeaf == null) { return(false); } Add(new Entry(fullPath, 1, DateTime.Now.ToFileTimeUtc(), checkIsLeaf(fullPath))); return(true); } return(UpdateEntry(id)); }