Ejemplo n.º 1
0
        /**
         * <summary>Returns a list of keys stored at this node that exist between the
         * two addresses.  Such keys returned are the storest path between the two
         * addresses.</summary>
         * <param name="add1">One of the address end points.</param>
         * <param name="add2">Another of the address end points.</param>
         * <returns>A LinkedList of key entries between add1 and add2</returns>
         */
        public LinkedList <MemBlock> GetKeysBetween(AHAddress add1, AHAddress add2)
        {
            LinkedList <MemBlock> keys = new LinkedList <MemBlock>();

            if (add1.IsRightOf(add2))
            {
                foreach (MemBlock key in list_of_keys)
                {
                    AHAddress key_addr = new AHAddress(key);
                    if (key_addr.IsBetweenFromLeft(add1, add2))
                    {
                        keys.AddLast(key);
                    }
                }
            }
            else
            {
                foreach (MemBlock key in list_of_keys)
                {
                    AHAddress key_addr = new AHAddress(key);
                    if (key_addr.IsBetweenFromRight(add1, add2))
                    {
                        keys.AddLast(key);
                    }
                }
            }
            return(keys);
        }
Ejemplo n.º 2
0
        //returns true if addr is in a given range including boundary.

        /**
         * This returns true if addr is between start and end in a ring.
         * IsBetweenFrom*() excludes both start and end, but InRange() includes both.
         * @param addr, this node's address
         * @param start, the beginning address of range
         * @param end, the ending address of range
         */
        public bool InRange(AHAddress addr, AHAddress start, AHAddress end)
        {
            return(addr.IsBetweenFromLeft(start, end) || addr.Equals(start) || addr.Equals(end));
        }
Ejemplo n.º 3
0
    /**
    <summary>Reassign range info(Start and End) based on recalculated range.</summary>
    <param name = "rg_size">Current range size(round distance between start address and end address of this CacheEntry).</param>
    <remarks>new_start = mid - rg_size/2, new_end = mid + rg_size/2 </remarks>
     */
    public void ReAssignRange(BigInteger rg_size) {
      AHAddress start_addr = (AHAddress)this.Start;
      AHAddress end_addr = (AHAddress)this.End;
      // calculate middle address of range
      BigInteger start_int = start_addr.ToBigInteger();
      BigInteger end_int = end_addr.ToBigInteger();
      BigInteger mid_int =  (start_int + end_int) / 2;  
      if (mid_int % 2 == 1) { mid_int = mid_int -1; }
      AHAddress mid_addr = new AHAddress(mid_int);
      if (!mid_addr.IsBetweenFromLeft(start_addr, end_addr)) {
        mid_int += Address.Half;
	mid_addr = new AHAddress(mid_int);
      }
      //addresses for new range
      BigInteger rg_half = rg_size / 2;
      if (rg_half % 2 == 1) { rg_half -= 1; }
      BigInteger n_st = mid_int - rg_half;
      /*
      if (n_st < 0) { //underflow
	n_st += AHAddress.Full; 
      }
      */
      BigInteger n_ed = n_st + rg_size;
      /*
      if (n_ed > AHAddress.Full) { //overflow
	n_ed -= AHAddress.Full; 
      }
      */
      /// underflow and overflow are handled by AHAddress class.
      AHAddress n_a = new AHAddress(n_st);
      AHAddress n_b = new AHAddress(n_ed);
      //Console.WriteLine("old range BigInt: ({0},{1}), new range Big Int ({2},{3})", up, down, n_st, n_ed);
      //Console.WriteLine("old range: ({0},{1}), new range({2},{3}), mid_addr: {4}", a,b,n_a,n_b, mid_addr);
      this.Start = n_a;
      this.End = n_b;
    }
Ejemplo n.º 4
0
 /**
 <summary>Returns a list of keys stored at this node that exist between the
 two addresses.  Such keys returned are the storest path between the two
 addresses.</summary>
 <param name="add1">One of the address end points.</param>
 <param name="add2">Another of the address end points.</param>
 <returns>A LinkedList of key entries between add1 and add2</returns>
 */
 public LinkedList<MemBlock> GetKeysBetween(AHAddress add1, AHAddress add2) {
   LinkedList<MemBlock> keys = new LinkedList<MemBlock>();
   if(add1.IsRightOf(add2)) {
     foreach(MemBlock key in list_of_keys) {
       AHAddress key_addr = new AHAddress(key);
       if(key_addr.IsBetweenFromLeft(add1, add2)) {
         keys.AddLast(key);
       }
     }
   }
   else {
     foreach(MemBlock key in list_of_keys) {
       AHAddress key_addr = new AHAddress(key);
       if(key_addr.IsBetweenFromRight(add1, add2)) {
         keys.AddLast(key);
       }
     }
   }
   return keys;
 }