Exemple #1
0
        public static NodeRefererEntry arrayClear(NodeRefererEntry refererEntry)
        {
            Ensure.ensure(refererEntry.entry.isBranch);

            ImmutableNodeReferer resultReferer = ImmutableNodeReferer.makeBranch(new List <ImmutableNodeReferer>());

            return(new NodeRefererEntry(resultReferer));
        }
Exemple #2
0
        /**
         * inserts the elements at the corresponding indices into the array referenced by "refererEntry"
         * and returns a new NodeRefererEntry which points at the "ImmutableNodeReferer" which desribes the result array
         *
         * indices must be sorted!
         *
         * \param refererEntry the target where the elements are inserted into
         * \param indices array of indices, must be sorted by index
         */
        public static NodeRefererEntry arrayRemove(NodeRefererEntry refererEntry, IList <int> indices)
        {
            Ensure.ensure(refererEntry.entry.isBranch);

            ImmutableNodeReferer resultReferer = ImmutableNodeRefererManipulatorHelper.copy(refererEntry.entry);

            int?previousIdx = null;

            // we iterate from elements with high indices to low because we don't have to keep track of index changes
            foreach (int idx in indices.Reverse())
            {
                Ensure.ensureHard(previousIdx.HasValue ? idx < previousIdx : true); // make sure the index is smaller than the previous one

                Ensure.ensure(idx < resultReferer.children.Count());
                resultReferer.children = resultReferer.children.RemoveAt(idx);

                previousIdx = idx;
            }

            return(new NodeRefererEntry(resultReferer));
        }
Exemple #3
0
        /**
         * inserts the elements at the corresponding indices into the array referenced by "refererEntry"
         * and returns a new NodeRefererEntry which points at the "ImmutableNodeReferer" which desribes the result array
         *
         * indices must be sorted!
         *
         * \param refererEntry the target where the elements are inserted into
         * \param elementsWithIndices array of elements with indices, must be sorted by index
         */
        public static NodeRefererEntry arrayInsert(NodeRefererEntry refererEntry, IList <Tuple <int, ImmutableNodeReferer> > elementsWithIndices)
        {
            Ensure.ensure(refererEntry.entry.isBranch);

            ImmutableNodeReferer resultReferer = ImmutableNodeRefererManipulatorHelper.copy(refererEntry.entry);

            int?previousIdx = null;

            // we iterate from elements with high indices to low because we don't have to keep track of index changes

            foreach (var iElementWithIndex in elementsWithIndices.Reverse())
            {
                int idx = iElementWithIndex.Item1;
                ImmutableNodeReferer nodeReferer = iElementWithIndex.Item2;

                Ensure.ensureHard(previousIdx.HasValue ? idx < previousIdx : true); // make sure the index is smaller than the previous one

                resultReferer.children = resultReferer.children.Insert(idx, nodeReferer);

                previousIdx = idx;
            }

            return(new NodeRefererEntry(resultReferer));
        }
Exemple #4
0
 public static NodeRefererEntry arrayRemove(NodeRefererEntry refererEntry, int index)
 {
     return(arrayRemove(refererEntry, new List <int> {
         index
     }));
 }
Exemple #5
0
 public static NodeRefererEntry arrayInsert(NodeRefererEntry refererEntry, int idx, ImmutableNodeReferer insert)
 {
     return(arrayInsert(refererEntry, new List <Tuple <int, ImmutableNodeReferer> > {
         new Tuple <int, ImmutableNodeReferer>(idx, insert)
     }));
 }