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); } }
// 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; } } }
public IEnumerable <T> Search(byte[] targetId, int count) { if (_baseNode == null) { throw new ArgumentNullException("BaseNode"); } if (_baseNode.Id == null) { throw new ArgumentNullException("BaseNode.Id"); } if (targetId == null) { throw new ArgumentNullException("targetId"); } if (count < 0) { throw new ArgumentOutOfRangeException("count"); } lock (this.ThisLock) { return(Kademlia <T> .Search(targetId, _baseNode.Id, this.ToArray(), count)); } }