public void SetNewHashFunction(LSHashFunction hashFunction) { lock (accessLock) { Dictionary <CustomBitArray, LSHashTableCell> oldValues = _values; _values = new Dictionary <CustomBitArray, LSHashTableCell>(); _hashFunction = hashFunction; //Re-hash all the old tweets using the new hash function foreach (LSHashTableCell oldCell in oldValues.Values) { foreach (LSHashTweet tweet in oldCell.GetTweets()) { bool anyTrue = false; CustomBitArray hash = _hashFunction.CalculateHashScore(tweet.Vector, out anyTrue); LSHashTableCell cell; if (_values.TryGetValue(hash, out cell)) { cell.Add(tweet); } else { cell = new LSHashTableCell(_cellCapacity); cell.Add(tweet); _values.Add(hash, cell); } } } } }
public void SetNewHashFunction(LSHashFunction hashFunction) { lock (accessLock) { Dictionary<CustomBitArray, LSHashTableCell> oldValues = _values; _values = new Dictionary<CustomBitArray, LSHashTableCell>(); _hashFunction = hashFunction; //Re-hash all the old tweets using the new hash function foreach (LSHashTableCell oldCell in oldValues.Values) { foreach (LSHashTweet tweet in oldCell.GetTweets()) { bool anyTrue = false; CustomBitArray hash = _hashFunction.CalculateHashScore(tweet.Vector, out anyTrue); LSHashTableCell cell; if (_values.TryGetValue(hash, out cell)) { cell.Add(tweet); } else { cell = new LSHashTableCell(_cellCapacity); cell.Add(tweet); _values.Add(hash, cell); } } } } }
/// <summary> /// Adds the vector to the hashtable and returns any previously added tweets with the same hash value /// </summary> /// <param name="vector"></param> /// <returns></returns> public List <LSHashTweet> Add(LSHashTweet tweet, out bool anyTrue) { lock (accessLock) { CustomBitArray hash = _hashFunction.CalculateHashScore(tweet.Vector, out anyTrue); LSHashTableCell cell; if (_values.TryGetValue(hash, out cell)) { List <LSHashTweet> neighbors = cell.GetTweets(); cell.Add(tweet); _lastUpdatedCell = cell; if (anyTrue) { return(neighbors); } return(new List <LSHashTweet>()); } else { cell = new LSHashTableCell(_cellCapacity); cell.Add(tweet); _values.Add(hash, cell); _lastUpdatedCell = cell; return(new List <LSHashTweet>()); } } }