Exemple #1
0
        public bool Contains(K key)
        {
            Guarder.CheckNull(key);
            var found = false;
            var node  = root;

            while (null != node)
            {
                var cmp = Comparer(key, node.Item.Key);
                if (cmp == 0)
                {
                    found = true;
                    break;
                }
                else if (cmp < 0)
                {
                    node = node.Left;
                }
                else // cmp > 0
                {
                    node = node.Right;
                }
            }

            return(found);
        }
        public virtual bool Remove(K key)
        {
            Guarder.CheckNull(key);
            var removed = false;
            var index   = HashIndex(key);
            var entry   = Entries[index];

            if (null != entry)
            {
                if (Equator.Equals(entry.Key, key))
                {
                    Entries[index] = entry.Next;
                    removed        = true;
                }
                else
                {
                    while (null != entry.Next)
                    {
                        var item = entry.Next;
                        if (Equator.Equals(item.Key, key))
                        {
                            entry.Next = item.Next;
                            removed    = true;
                            break;
                        }
                        entry = item;
                    }
                }
            }
            if (removed)
            {
                Count--;
            }
            return(removed);
        }
        public virtual bool ContainsKey(K key)
        {
            Guarder.CheckNull(key);
            var entry = GetEntry(key);

            return(entry != null);
        }
Exemple #4
0
        public KeyValuePair <K, V> Floor(K key)
        {
            Guarder.CheckNull(key);
            ValidateNotEmpty();
            var node  = root;
            var found = false;

            while (null != node)
            {
                var cmp = Comparer(key, node.Item.Key);
                if (cmp >= 0)
                {
                    if (node.Right == null || Comparer(key, Minimum(node.Right).Item.Key) < 0)
                    {
                        found = true;
                        break;
                    }
                    node = node.Right;
                }
                else
                {
                    node = node.Left;
                }
            }

            if (!found)
            {
                throw new ArgumentException(string.Format("No item is the floor of the key: {0}", key));
            }

            return(node.Item);
        }
Exemple #5
0
        public bool Remove(K key)
        {
            Guarder.CheckNull(key);
            var index = HashIndex(key);
            var found = false;

            while (entries[index].Occupied)
            {
                if (!entries[index].Deleted && comparer.Equals(entries[index].Key, key))
                {
                    entries[index].Deleted = true;
                    entries[index].Key     = default(K);
                    entries[index].Value   = default(V);
                    Count--;
                    found = true;
                    break;
                }
                index = (index + 1) & (capacity - 1);
            }
            if (!found)
            {
                index++;
            }

            return(found);
        }
Exemple #6
0
 public V this[K key]
 {
     get
     {
         Guarder.CheckNull(key);
         var found = GetNode(root, key);
         if (null == found)
         {
             throw new KeyNotFoundException(string.Format("The key {0} does not exist in the map.", key));
         }
         return(found.Item.Value);
     }
     set
     {
         Guarder.CheckNull(key);
         var found = GetNode(root, key);
         if (null == found)
         {
             Add(key, value);
         }
         else
         {
             found.Item = new KeyValuePair <K, V>(key, value);
         }
     }
 }
 public ConcurrentListBasedMap(IComparer <K> comparer)
 {
     Guarder.CheckNull(comparer, "comparer");
     this.comparer = comparer;
     head          = new LockableNode();
     tail          = new LockableNode();
     head.Next     = tail;
 }
Exemple #8
0
        public bool ContainsKey(K key)
        {
            Guarder.CheckNull(key);
            var index = FindEntry(key);
            var entry = entries[index];

            return(entry.Occupied);
        }
        protected virtual V Get(K key)
        {
            Guarder.CheckNull(key);
            var entry = GetEntry(key);

            entry.Validate(x => x != null, new KeyNotFoundException(string.Format(Messages.KeyDoesNotExistInMap, key)));
            return(entry.Value);
        }
Exemple #10
0
 public void CopyTo(KeyValuePair <K, V>[] array, int arrayIndex)
 {
     Guarder.CheckNull(array);
     foreach (var item in this)
     {
         array[arrayIndex++] = item;
     }
 }
Exemple #11
0
        public static string ToJson <T>(T target, Transformer <T, JValue> transform)
        {
            Guarder.CheckNull(transform, "transform");
            Guarder.CheckNull(target, "target");
            var value = transform(target);

            return(value.ToString());
        }
        public bool ContainsKey(K key)
        {
            Guarder.CheckNull(key, "key");
            LockableNode pred, curr;

            Find(key, out pred, out curr);
            return(!IsNotFound(pred, curr) && (comparer.Compare(curr.Key, key) == 0 && !curr.Marked));
        }
Exemple #13
0
        public static string ToJson <T>(T target, IObjectConverter <T> converter)
        {
            Guarder.CheckNull(converter, "converter");
            Guarder.CheckNull(target, "target");
            var value = converter.Convert(target);

            return(value.ToString());
        }
Exemple #14
0
        public static T To <T>(string json, IJsonConverter <T> converter)
        {
            Guarder.CheckNull(converter, "converter");
            var engine = new ParseEngine();
            var value  = engine.Parse(json);

            return(converter.Convert(value));
        }
Exemple #15
0
        public static T To <T>(string json, Transformer <JValue, T> transform)
        {
            Guarder.CheckNull(transform, "transform");
            var engine = new ParseEngine();
            var value  = engine.Parse(json);

            return(transform(value));
        }
 public ConcurrentSortedList(IComparer <T> comparer)
 {
     Guarder.CheckNull(comparer, "comparer");
     head          = new Node();
     tail          = new Node();
     head.Next     = new AtomicMarkableReference <Node>(tail);
     tail.Next     = new AtomicMarkableReference <Node>(null);
     this.comparer = comparer;
 }
Exemple #17
0
 public void Add(K key, V value)
 {
     Guarder.CheckNull(key);
     if (Count >= threshold)
     {
         Inflate();
     }
     Enroute(key, value);
 }
 protected AbstractHashedMap(int capacity, IEqualityComparer <K> equator)
 {
     capacity.Validate(x => x > 0, new ArgumentException("Capacity must be larger than 0."));
     Guarder.CheckNull(equator);
     Count    = 0;
     Capacity = CalculateCapacity(capacity);
     Equator  = equator;
     Entries  = new HashEntry[this.Capacity];
 }
        public void Add(T key)
        {
            Guarder.CheckNull(key, "key");
            var spin = new SpinWait();

            while (!Insert(key))
            {
                spin.SpinOnce();
            }
        }
        public virtual void CopyTo(KeyValuePair <K, V>[] array, int arrayIndex)
        {
            Guarder.CheckNull(array);
            var index = 0;

            foreach (var entry in this)
            {
                array[arrayIndex + (index++)] = entry;
            }
        }
Exemple #21
0
        /// <summary>
        /// Copies the items in the set to an array, start from the arrayIndex.
        /// </summary>
        /// <param name="array">The array to which items are copied.</param>
        /// <param name="arrayIndex">The index to start to copy the items.</param>
        public override void CopyTo(T[] array, int arrayIndex)
        {
            Guarder.CheckNull(array);
            var index = arrayIndex;

            foreach (var i in llrbTree)
            {
                array[index++] = i.Key;
            }
        }
Exemple #22
0
        public bool TryGetValue(K key, out V value)
        {
            Guarder.CheckNull(key);
            var index = FindEntry(key);
            var entry = entries[index];

            value = entry.Value;

            return(entry.Occupied);
        }
Exemple #23
0
 public int Compare([AllowNull] Guarder <T> x, [AllowNull] Guarder <T> y)
 {
     if (x.minimum && !y.minimum)
     {
         return(-1);
     }
     else
     {
         return(comparer.Compare(x.value, y.value));
     }
 }
Exemple #24
0
 public IJsonObjectMapper <T> With(string jsonKey)
 {
     Guarder.CheckNull(jsonKey, "jsonKey");
     if (lastExp == null)
     {
         throw new InvalidOperationException(Messages.NoPropertyToMap);
     }
     Map(jsonKey, lastExp);
     lastExp = null;
     return(this);
 }
Exemple #25
0
        private void Main_Load(object sender, EventArgs e)
        {
            //Initilize MW3Guard core
            MW3_BOT = new Guarder(PS3);

            MW3_GUARDER.Interval = 500; //Upd8 leaderboard every half sec.
            MW3_GUARDER.Tick    += new EventHandler(guarder);

            PS3.ChangeAPI(SelectAPI.ControlConsole); //Sorry dude, this will only work with CCAPI.
            //You could try to convert it to TMAPI if you wanted to.
        }
Exemple #26
0
 public HashedMap(int capacity, IEqualityComparer <K> comparer)
 {
     Guarder.CheckNull(comparer);
     if (capacity <= 0)
     {
         throw new ArgumentException("The capacity must be larger than zero.");
     }
     this.comparer = comparer;
     this.capacity = CalculateCapacity(capacity);
     Count         = 0;
     entries       = new Entry[this.capacity];
 }
 public virtual int this[T item]
 {
     get
     {
         Guarder.CheckNull(item);
         if (!Map.ContainsKey(item))
         {
             throw new ArgumentException("The item does not exist in the bag");
         }
         return(Map[item]);
     }
 }
 public Customized32HashedMap(IDictionary <K, V> items, IHashStrategy hasher, Transformer <K, byte[]> transformer, Equator <K> isEqual)
     : this(items == null ? DefaultCapacity : items.Count, hasher, transformer, isEqual)
 {
     Guarder.CheckNull(hasher, transformer, isEqual);
     if (null != items)
     {
         foreach (var item in items)
         {
             Add(item.Key, item.Value);
         }
     }
 }
        public virtual bool Remove(T item)
        {
            Guarder.CheckNull(item);
            var removed = false;

            if (Map.ContainsKey(item))
            {
                Map.Remove(item);
                removed = true;
            }
            return(removed);
        }
Exemple #30
0
        public void CopyTo(KeyValuePair <K, V>[] array, int arrayIndex)
        {
            Guarder.CheckNull(array);
            var index = 0;

            foreach (var element in entries)
            {
                if (element.Occupied)
                {
                    array[arrayIndex + (index++)] = new KeyValuePair <K, V>(element.Key, element.Value);
                }
            }
        }
Exemple #31
0
        private void Main_Load(object sender, EventArgs e)
        {
            //Initilize MW3Guard core
            MW3_BOT = new Guarder(PS3);

            MW3_GUARDER.Interval = 500; //Upd8 leaderboard every half sec.
            MW3_GUARDER.Tick += new EventHandler(guarder);

            PS3.ChangeAPI(SelectAPI.ControlConsole); //Sorry dude, this will only work with CCAPI.
            //You could try to convert it to TMAPI if you wanted to.
        }