You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Zero/ZeroLevel.HNSW/Services/VectorSet.cs

32 lines
710 B

3 years ago
using System.Collections.Generic;
using System.Threading;
namespace ZeroLevel.HNSW
{
public class VectorSet<T>
{
public IList<T> _set = new List<T>();
public T this[int index] => _set[index];
SpinLock _lock = new SpinLock();
public int Append(T vector)
{
bool gotLock = false;
gotLock = false;
try
{
_lock.Enter(ref gotLock);
_set.Add(vector);
return _set.Count - 1;
}
finally
{
// Only give up the lock if you actually acquired it
if (gotLock) _lock.Exit();
}
}
}
}

Powered by TurnKey Linux.