Skip to content

Commit

Permalink
Update WexflowService.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
aelassas committed Jul 5, 2023
1 parent e6f181f commit 4b8dd6b
Show file tree
Hide file tree
Showing 5 changed files with 177 additions and 192 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ private readonly void Sort()
Array.Sort(_changes, 0, _count, Comparer.Default);
}

public override readonly string ToString()
public readonly override string ToString()
{
return _count.ToString();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public FileState(string directory, string path) : this()
Path = path;
}

public override readonly string ToString()
public readonly override string ToString()
{
return Path;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ internal class PathToFileStateHashtable
{
private int _nextValuesIndex = 1; // the first Values slot is reserved so that default(Bucket) knows that it is not pointing to any value.
public FileState[] Values { get; private set; }
private Bucket[] Buckets;
private Bucket[] _buckets;

public PathToFileStateHashtable(int capacity = 4)
{
Expand All @@ -26,7 +26,7 @@ public PathToFileStateHashtable(int capacity = 4)
// +1 is needed so that there are always more buckets than values.
// this is so that unsuccesful search always terminates (as it terminates at an empty bucket)
// note that today the "+1" is not strictly required, as one Values slot is reserved, but I am future proofing here
Buckets = new Bucket[GetPrime(capacity + 1)];
_buckets = new Bucket[GetPrime(capacity + 1)];
}

public int Count { get; private set; }
Expand All @@ -43,9 +43,9 @@ public void Add(string directory, string file, FileState value)

while (true)
{
if (Buckets[bucket].IsEmpty)
if (_buckets[bucket].IsEmpty)
{
Buckets[bucket] = new Bucket(directory, file, _nextValuesIndex);
_buckets[bucket] = new Bucket(directory, file, _nextValuesIndex);
Count++;
_nextValuesIndex++;
return;
Expand All @@ -69,13 +69,13 @@ public int IndexOf(string directory, ReadOnlySpan<char> file)
var bucket = ComputeBucket(file);
while (true)
{
var valueIndex = Buckets[bucket].ValuesIndex;
var valueIndex = _buckets[bucket].ValuesIndex;
if (valueIndex == 0)
{
return -1; // not found
}

if (Equal(Buckets[bucket].Key, directory, file))
if (Equal(_buckets[bucket].Key, directory, file))
{
if (Values[valueIndex].Path != null)
{
Expand All @@ -90,7 +90,7 @@ public int IndexOf(string directory, ReadOnlySpan<char> file)
private int NextCandidateBucket(int bucket)
{
bucket++;
if (bucket >= Buckets.Length)
if (bucket >= _buckets.Length)
{
bucket = 0;
}
Expand Down Expand Up @@ -128,7 +128,7 @@ private int ComputeBucket(ReadOnlySpan<char> file)
hash = int.MaxValue;
}

var bucket = Math.Abs(hash) % Buckets.Length;
var bucket = Math.Abs(hash) % _buckets.Length;
return bucket;
}

Expand All @@ -144,12 +144,12 @@ private void Resize()
bigger.Add(existingValue.Directory, existingValue.Path, existingValue);
}
Values = bigger.Values;
Buckets = bigger.Buckets;
_buckets = bigger._buckets;
_nextValuesIndex = bigger._nextValuesIndex;
Count = bigger.Count;
}

private static readonly int[] primes = {
private static readonly int[] Primes = {
3, 7, 11, 17, 23, 29, 37, 47, 59, 71, 89, 107, 131, 163, 197, 239, 293, 353, 431, 521, 631, 761, 919,
1103, 1327, 1597, 1931, 2333, 2801, 3371, 4049, 4861, 5839, 7013, 8419, 10103, 12143, 14591,
17519, 21023, 25229, 30293, 36353, 43627, 52361, 62851, 75431, 90523, 108631, 130363, 156437,
Expand All @@ -175,9 +175,9 @@ private static bool IsPrime(int candidate)

private static int GetPrime(int min)
{
for (var i = 0; i < primes.Length; i++)
for (var i = 0; i < Primes.Length; i++)
{
var prime = primes[i];
var prime = Primes[i];
if (prime >= min)
{
return prime;
Expand Down Expand Up @@ -246,7 +246,7 @@ public Bucket(string directory, string file, int valueIndex)
}
public readonly bool IsEmpty => ValuesIndex == 0;

public override readonly string ToString()
public readonly override string ToString()
{
return IsEmpty ? "empty" : Key.ToString();
}
Expand All @@ -258,7 +258,7 @@ private struct FullPath
public string Directory;
public string File;

public override readonly string ToString()
public readonly override string ToString()
{
return File;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ public class PollingFileSystemWatcher : IDisposable, ISerializable
private Timer _timer;
private readonly PathToFileStateHashtable _state; // stores state of the directory
private long _version; // this is used to keep track of removals. // TODO: describe the algorithm
private bool _started = false;
private bool _disposed = false;
private bool _started;
private bool _disposed;
private long _pollingInterval = 1000;

/// <summary>
Expand All @@ -57,12 +57,12 @@ public PollingFileSystemWatcher(string path, string filter = "*", EnumerationOpt
Path = path;
Filter = filter ?? throw new ArgumentNullException(nameof(filter));
EnumerationOptions = options ?? new EnumerationOptions();
_timer = new Timer(new TimerCallback(TimerHandler));
_timer = new Timer(TimerHandler);
}

private void Initialize()
{
_timer = new Timer(new TimerCallback(TimerHandler));
_timer = new Timer(TimerHandler);
if (!_started)
{
return;
Expand Down Expand Up @@ -255,7 +255,7 @@ protected PollingFileSystemWatcher(SerializationInfo info, StreamingContext cont
Filter = info.GetString(nameof(Filter));
EnumerationOptions = new EnumerationOptions { RecurseSubdirectories = info.GetBoolean(nameof(EnumerationOptions.RecurseSubdirectories)) };

_timer = new Timer(new TimerCallback(TimerHandler));
_timer = new Timer(TimerHandler);
PollingInterval = info.GetInt32(nameof(PollingInterval));
}

Expand Down
Loading

0 comments on commit 4b8dd6b

Please sign in to comment.