public static ImmutableNodeReferer makeNonbranch(ValueNode referencedValueNode) { ImmutableNodeReferer result = new ImmutableNodeReferer(); result.referencedValueNode = referencedValueNode; return(result); }
public static NodeRefererEntry arrayClear(NodeRefererEntry refererEntry) { Ensure.ensure(refererEntry.entry.isBranch); ImmutableNodeReferer resultReferer = ImmutableNodeReferer.makeBranch(new List <ImmutableNodeReferer>()); return(new NodeRefererEntry(resultReferer)); }
public static ImmutableNodeReferer makeImmutableNodeRefererForArray(IList <Variant> values) { var resultChildren = new List <ImmutableNodeReferer>(new ImmutableNodeReferer[values.Count]); for (int i = 0; i < values.Count; i++) { resultChildren[i] = ImmutableNodeReferer.makeNonbranch(ValueNode.makeAtomic(values[i])); } return(ImmutableNodeReferer.makeBranch(resultChildren)); }
public static ImmutableNodeReferer makeString(string value) { ImmutableNodeReferer result = ImmutableNodeReferer.makeBranch(); result.children = result.children.Add(ImmutableNodeReferer.makeNonbranch(ValueNode.makeDatatype("string"))); for (int i = 0; i < value.Length; i++) { result.children = result.children.Add(ImmutableNodeReferer.makeNonbranch(ValueNode.makeAtomic(Variant.makeInt(value[i])))); } return(result); }
// shallow copie of branch or just passthrough if element is nonbranch // doesn't touch parent public static ImmutableNodeReferer copy(ImmutableNodeReferer element) { if (!element.isBranch) { return(element); } ImmutableNodeReferer result = ImmutableNodeReferer.makeBranch(); // copy for (int i = 0; i < element.children.Count(); i++) { result.children = result.children.Add(element.children[i]); } return(result); }
/** * 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)); }
//////////// // static helper functions internal static bool checkEquality(ImmutableNodeReferer a, ImmutableNodeReferer b) { if (a.isBranch != b.isBranch) { return(false); } if (a.isBranch) { if (a.children.Count() != b.children.Count()) { return(false); } for (int i = 0; i < a.children.Count(); i++) { if (!checkEquality(a.children[i], b.children[i])) { return(false); } } } else { if (a.type != b.type) { return(false); } if (!a.value.checkEquality(b.value)) { return(false); } } return(true); }
/** * 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)); }
public static NodeRefererEntry arrayInsert(NodeRefererEntry refererEntry, int idx, ImmutableNodeReferer insert) { return(arrayInsert(refererEntry, new List <Tuple <int, ImmutableNodeReferer> > { new Tuple <int, ImmutableNodeReferer>(idx, insert) })); }
public static NodeRefererEntry makeImmutableArray(IList <Variant> values) { ImmutableNodeReferer entryNodeReferer = ImmutableNodeRefererManipulatorHelper.makeImmutableNodeRefererForArray(values); return(new NodeRefererEntry(entryNodeReferer)); }
public NodeRefererEntry(ImmutableNodeReferer entry) { this.entry = entry; }