public bool AddAll(int index, DoubleBag other) { // throws NullPointerException if other == null, // ArrayArrayIndexOutOfBoundsException if index < 0, // and ArrayIndexOutOfBoundsException if index > numObjs if (index > NumObjs) { throw new ArgumentOutOfRangeException(index.ToString()); } //{ throwArrayIndexOutOfBoundsException(index); } if (other.NumObjs <= 0) { return(false); } // make DoubleBag big enough if (NumObjs + other.NumObjs > Objs.Length) { Resize(NumObjs + other.NumObjs); } if (index != NumObjs) // scoot over elements if we're inserting in the middle { Array.Copy(Objs, index, Objs, index + other.Size, NumObjs - index); } Array.Copy(other.Objs, 0, Objs, index, other.NumObjs); NumObjs += other.NumObjs; return(true); }
/** Adds the doubles from the other DoubleBag without copying them. The size of the * new DoubleBag is the minimum necessary size to hold the doubles. If the Other DoubleBag is * null, a new empty DoubleBag is created. */ public DoubleBag(DoubleBag other) { if (other == null) { NumObjs = 0; Objs = new double[1]; } else { NumObjs = other.NumObjs; Objs = new double[NumObjs]; Array.Copy(other.Objs, 0, Objs, 0, NumObjs); } }
public bool AddAll(DoubleBag other) { return(AddAll(NumObjs, other)); }