예제 #1
0
        public override object DeleteKeyForLeafNode(IKeyAndValue keyAndValue)
        {
            var objectHasBeenFound = false;
            var positionOfKey      = GetPositionOfKey(keyAndValue.GetKey());

            if (positionOfKey < 0)
            {
                return(null);
            }

            var realPosition = positionOfKey - 1;
            // In Multiple Values per key, the value is a list
            var value = (IList)Values[realPosition];
            // Here we must search for the right object. The list can contains more than 1 object

            var size = value.Count;

            for (var i = 0; i < size && !objectHasBeenFound; i++)
            {
                if (!value[i].Equals(keyAndValue.GetValue()))
                {
                    continue;
                }

                value.Remove(i);
                objectHasBeenFound = true;
            }
            if (!objectHasBeenFound)
            {
                return(null);
            }

            // If after removal, the list is empty, then remove the key from the node
            if (value.Count == 0)
            {
                // If we get there
                LeftShiftFrom(realPosition, false);
                NbKeys--;
            }

            BTreeValidator.ValidateNode(this);
            return(keyAndValue.GetValue());
        }
예제 #2
0
        public override object DeleteKeyForLeafNode(IKeyAndValue keyAndValue)
        {
            var objectHasBeenFound = false;
            var positionOfKey = GetPositionOfKey(keyAndValue.GetKey());

            if (positionOfKey < 0)
                return null;

            var realPosition = positionOfKey - 1;
            // In Multiple Values per key, the value is a list
            var value = (IList) Values[realPosition];
            // Here we must search for the right object. The list can contains more than 1 object

            var size = value.Count;
            for (var i = 0; i < size && !objectHasBeenFound; i++)
            {
                if (!value[i].Equals(keyAndValue.GetValue()))
                    continue;

                value.Remove(i);
                objectHasBeenFound = true;
            }
            if (!objectHasBeenFound)
            {
                return null;
            }

            // If after removal, the list is empty, then remove the key from the node
            if (value.Count == 0)
            {
                // If we get there
                LeftShiftFrom(realPosition, false);
                NbKeys--;
            }

            BTreeValidator.ValidateNode(this);
            return keyAndValue.GetValue();
        }
예제 #3
0
 public virtual void SetKeyAndValueAt(IKeyAndValue keyAndValue, int index, bool shiftIfAlreadyExist, bool incrementNbKeys)
 {
     SetKeyAndValueAt(keyAndValue.GetKey(), keyAndValue.GetValue(), index, shiftIfAlreadyExist, incrementNbKeys);
 }
예제 #4
0
 public virtual void SetKeyAndValueAt(IKeyAndValue keyAndValue, int index)
 {
     SetKeyAndValueAt(keyAndValue.GetKey(), keyAndValue.GetValue(), index);
 }
예제 #5
0
 public virtual void SetKeyAndValueAt(IKeyAndValue keyAndValue, int index, bool shiftIfAlreadyExist, bool incrementNbKeys)
 {
     SetKeyAndValueAt(keyAndValue.GetKey(), keyAndValue.GetValue(), index, shiftIfAlreadyExist, incrementNbKeys);
 }
예제 #6
0
 public virtual void SetKeyAndValueAt(IKeyAndValue keyAndValue, int index)
 {
     SetKeyAndValueAt(keyAndValue.GetKey(), keyAndValue.GetValue(), index);
 }