示例#1
0
        public bool Remove(T item)
        {
            if (item == null)
            {
                throw new ArgumentNullException("item");
            }
            if (item.Id == null)
            {
                throw new ArgumentNullException("item.Id");
            }

            lock (this.ThisLock)
            {
                int i = Kademlia <T> .Distance(this.BaseNode.Id, item.Id) - 1;

                if (i == -1)
                {
                    return(false);
                }

                var targetList = _nodesList[i];

                if (targetList != null)
                {
                    return(targetList.Remove(item));
                }

                return(false);
            }
        }
示例#2
0
        // Addより優先的に
        public void Live(T item)
        {
            if (_baseNode == null)
            {
                throw new ArgumentNullException("BaseNode");
            }
            if (_baseNode.Id == null)
            {
                throw new ArgumentNullException("BaseNode.Id");
            }
            if (item == null)
            {
                throw new ArgumentNullException("item");
            }
            if (item.Id == null)
            {
                throw new ArgumentNullException("item.Id");
            }

            lock (this.ThisLock)
            {
                int i = Kademlia <T> .Distance(this.BaseNode.Id, item.Id) - 1;

                if (i == -1)
                {
                    return;
                }

                var targetList = _nodesList[i];

                // 生存率の高いNodeはFirstに、そうでないNodeはLastに
                if (targetList != null)
                {
                    var orignal = targetList.FirstOrDefault(n => Unsafe.Equals(n.Id, item.Id));

                    if (orignal != null)
                    {
                        targetList.Remove(orignal);
                        targetList.AddFirst(item);
                    }
                    else
                    {
                        if (targetList.Count == _column)
                        {
                            targetList.RemoveLast();
                        }

                        targetList.AddFirst(item);
                    }
                }
                else
                {
                    targetList = new LinkedList <T>();
                    targetList.AddFirst(item);
                    _nodesList[i] = targetList;
                }
            }
        }