Example #1
0
 /// <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>();
         }
     }
 }
Example #2
0
        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);
                        }
                    }
                }
            }
        }
Example #3
0
 /// <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>());
         }
     }
 }
Example #4
0
 public void UndoLastAdd()
 {
     if (_lastUpdatedCell != null)
     {
         _lastUpdatedCell.UndoLastAdd();
     }
     _lastUpdatedCell = null;
 }
Example #5
0
 public void UndoLastAdd()
 {
     if (_lastUpdatedCell != null)
         _lastUpdatedCell.UndoLastAdd();
     _lastUpdatedCell = null;
 }
Example #6
0
        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())
                    {
                        CustomBitArray hash = _hashFunction.CalculateHashScore(tweet.Vector);
                        LSHashTableCell cell;
                        if (_values.TryGetValue(hash, out cell))
                        {
                            cell.Add(tweet);
                        }
                        else
                        {
                            cell = new LSHashTableCell(_cellCapacity);
                            cell.Add(tweet);
                            _values.Add(hash, cell);
                        }
                    }
                }
            }
        }