Ejemplo n.º 1
0
 public bool Add(Actor actor)
 {
     if (this.Contains(actor))
     {
         return(false);
     }
     else
     {
         ++this.numActors;
         ActorSet.ListNode newNode = new ActorSet.ListNode(actor,
                                                           this.listHeadTail.prev);
         int seq = actor.GetSequenceNumber();
         if (this.numActors >= 2 * this.hashMap.Length)
         {
             this.Resize();
         }
         else
         {
             int hash = seq % this.hashMap.Length;
             ActorSet.ListNode hashHead = this.hashMap[hash];
             this.hashMap[hash] = newNode;
             newNode.SetHashListHead(hashHead);
         }
         this.code += seq;
         return(true);
     }
 }
Ejemplo n.º 2
0
        private ActorSet.ListNode GetActorNode(Actor actor)
        {
            if (this.hashMap.Length == 0)
            {
                return(null);
            }
            else
            {
                int seq  = actor.GetSequenceNumber();
                int hash = seq % this.hashMap.Length;
                ActorSet.ListNode hashHead = this.hashMap[hash];
                if (hashHead == null)
                {
                    return(null);
                }
                else if (hashHead.actor == actor)
                {
                    return(hashHead);
                }
                else
                {
                    for (ActorSet.ListNode curNode = hashHead.nextHash; curNode != hashHead; curNode = curNode.nextHash)
                    {
                        if (curNode.actor == actor)
                        {
                            return(curNode);
                        }
                    }

                    return(null);
                }
            }
        }
Ejemplo n.º 3
0
 public void Remove()
 {
     this.next.prev         = this.prev;
     this.prev.next         = this.next;
     this.nextHash.prevHash = this.prevHash;
     this.prevHash.nextHash = this.nextHash;
 }
Ejemplo n.º 4
0
 public bool Add(Actor actor)
 {
     if (this.Contains(actor))
     {
         return false;
     }
     else
     {
         ++this.numActors;
         ActorSet.ListNode newNode = new ActorSet.ListNode(actor,
                 this.listHeadTail.prev);
         int seq = actor.GetSequenceNumber();
         if (this.numActors >= 2 * this.hashMap.Length)
         {
             this.Resize();
         }
         else
         {
             int hash = seq % this.hashMap.Length;
             ActorSet.ListNode hashHead = this.hashMap[hash];
             this.hashMap[hash] = newNode;
             newNode.SetHashListHead(hashHead);
         }
         this.code += seq;
         return true;
     }
 }
Ejemplo n.º 5
0
 public ListNode(Actor actor, ActorSet.ListNode listTail)
 {
     this.actor     = actor;
     this.next      = listTail.next;
     this.prev      = listTail;
     listTail.next  = this;
     this.next.prev = this;
 }
Ejemplo n.º 6
0
 private void Resize(int size)
 {
     this.hashMap = new ActorSet.ListNode[size];
     for (ActorSet.ListNode currentActor = this.listHeadTail.next; currentActor != this.listHeadTail; currentActor = currentActor.next)
     {
         int seq  = currentActor.actor.GetSequenceNumber();
         int hash = seq % size;
         ActorSet.ListNode hashHead = this.hashMap[hash];
         this.hashMap[hash] = currentActor;
         currentActor.SetHashListHead(hashHead);
     }
 }
Ejemplo n.º 7
0
 public bool Remove(Actor actor)
 {
     ActorSet.ListNode actorNode = this.GetActorNode(actor);
     if (actorNode != null)
     {
         this.Remove(actorNode);
         this.code -= actor.GetSequenceNumber();
         return(true);
     }
     else
     {
         return(false);
     }
 }
Ejemplo n.º 8
0
 public void SetHashListHead(ActorSet.ListNode oldHead)
 {
     if (oldHead == null)
     {
         this.nextHash = this;
         this.prevHash = this;
     }
     else
     {
         this.nextHash          = oldHead;
         this.prevHash          = oldHead.prevHash;
         oldHead.prevHash       = this;
         this.prevHash.nextHash = this;
     }
 }
Ejemplo n.º 9
0
        public void AddAll(Actor[] o)
        {
            int size = o.Length;

            this.numActors = size;
            this.Resize();
            for (int i = 0; i < size; i++)
            {
                Actor             actor   = o[i];
                ActorSet.ListNode newNode = new ActorSet.ListNode(actor,
                                                                  this.listHeadTail.prev);
                int seq  = actor.GetSequenceNumber();
                int hash = seq % this.hashMap.Length;
                ActorSet.ListNode hashHead = this.hashMap[hash];
                this.hashMap[hash] = newNode;
                newNode.SetHashListHead(hashHead);
                this.code += seq;
            }
        }
Ejemplo n.º 10
0
        private void Remove(ActorSet.ListNode actorNode)
        {
            int seq  = actorNode.actor.GetSequenceNumber();
            int hash = seq % this.hashMap.Length;

            if (this.hashMap[hash] == actorNode)
            {
                this.hashMap[hash] = actorNode.nextHash;
                if (this.hashMap[hash] == actorNode)
                {
                    this.hashMap[hash] = null;
                }
            }

            actorNode.Remove();
            --this.numActors;
            if (this.numActors <= this.hashMap.Length / 2)
            {
                this.Resize();
            }
        }
Ejemplo n.º 11
0
 public object Next()
 {
     this.currentNode = this.currentNode.next;
     return(this.currentNode.actor);
 }
Ejemplo n.º 12
0
 public object Next()
 {
     this.currentNode = this.currentNode.next;
     return this.currentNode.actor;
 }
Ejemplo n.º 13
0
 public ActorSetIterator(ActorSet set)
 {
     this.actorSet = set;
     this.currentNode = actorSet.listHeadTail;
 }
Ejemplo n.º 14
0
 public void Remove()
 {
     this.next.prev = this.prev;
     this.prev.next = this.next;
     this.nextHash.prevHash = this.prevHash;
     this.prevHash.nextHash = this.nextHash;
 }
Ejemplo n.º 15
0
            public void SetHashListHead(ActorSet.ListNode oldHead)
            {
                if (oldHead == null)
                {
                    this.nextHash = this;
                    this.prevHash = this;
                }
                else
                {
                    this.nextHash = oldHead;
                    this.prevHash = oldHead.prevHash;
                    oldHead.prevHash = this;
                    this.prevHash.nextHash = this;
                }

            }
Ejemplo n.º 16
0
 public ListNode(Actor actor, ActorSet.ListNode listTail)
 {
     this.actor = actor;
     this.next = listTail.next;
     this.prev = listTail;
     listTail.next = this;
     this.next.prev = this;
 }
Ejemplo n.º 17
0
 public ListNode()
 {
     this.next = this;
     this.prev = this;
 }
Ejemplo n.º 18
0
 public void AddAll(Actor[] o)
 {
     int size = o.Length;
     this.numActors = size;
     this.Resize();
     for (int i = 0; i < size; i++)
     {
         Actor actor = o[i];
         ActorSet.ListNode newNode = new ActorSet.ListNode(actor,
                 this.listHeadTail.prev);
         int seq = actor.GetSequenceNumber();
         int hash = seq % this.hashMap.Length;
         ActorSet.ListNode hashHead = this.hashMap[hash];
         this.hashMap[hash] = newNode;
         newNode.SetHashListHead(hashHead);
         this.code += seq;
     }
 }
Ejemplo n.º 19
0
 public ListNode()
 {
     this.next = this;
     this.prev = this;
 }
Ejemplo n.º 20
0
 public ActorSetIterator(ActorSet set)
 {
     this.actorSet    = set;
     this.currentNode = actorSet.listHeadTail;
 }