Beispiel #1
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));
        }
Beispiel #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 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));
        }
Beispiel #3
0
        public static NodeRefererEntry makeImmutableArray(IList <Variant> values)
        {
            ImmutableNodeReferer entryNodeReferer = ImmutableNodeRefererManipulatorHelper.makeImmutableNodeRefererForArray(values);

            return(new NodeRefererEntry(entryNodeReferer));
        }