public void GenerateData(long maximumObjects, long maximumTags, long maximumTagsPerObject) { // Objects // (object1: object1 object) // Tags // (tag1: tag1 tag) // Objects to Tags // (object1 tag1) // (object1 tag2) // (object2 tag1) // (object2 tag2) var any = _links.Constants.Any; if (_links.Count(any, any, _object) == 0 && _links.Count(any, any, _tag) == 0) { // No data yet var itself = _links.Constants.Itself; // Generating Objects var objectsRangeStart = _links.Count() + 1; for (var i = 0L; i < maximumObjects; i++) { _links.CreateAndUpdate(itself, _object); } var objectsRangeEnd = _links.Count() + 1; _objectsRange = new Range <uint>(objectsRangeStart, objectsRangeEnd); // Generating Tags var tagsRangeStart = _links.Count() + 1; for (var i = 0L; i < maximumTags; i++) { _links.CreateAndUpdate(itself, _tag); } var tagsRangeEnd = _links.Count() + 1; _tagsRange = new Range <uint>(tagsRangeStart, tagsRangeEnd); // Generation Objects to Tags relationships var random = new Random(); for (var i = 0L; i < maximumObjects; i++) { var @object = (uint)(objectsRangeStart + i); for (var j = 0L; j < maximumTagsPerObject; j++) { var tag = (uint)random.Next((int)tagsRangeStart, (int)tagsRangeEnd); _links.GetOrCreate(@object, tag); } } } else { var cursor = 4U; _objectsRange = new Range <uint>(cursor, cursor += (uint)maximumObjects); _tagsRange = new Range <uint>(cursor, cursor += (uint)maximumTags); } }
public static TLink GetOrCreate <TLink>(this ILinks <TLink> links, TLink source, TLink target) { var link = links.SearchOrDefault(source, target); if (EqualityComparer <TLink> .Default.Equals(link, default)) { link = links.CreateAndUpdate(source, target); } return(link); }
private static void TestCharAndUnicodeSymbolConverters(ILinks <ulong> links, ulong meaningRoot, IConverter <ulong> addressToNumberConverter, IConverter <ulong> numberToAddressConverter) { var unicodeSymbolMarker = links.CreateAndUpdate(meaningRoot, links.Constants.Itself); var charToUnicodeSymbolConverter = new CharToUnicodeSymbolConverter <ulong>(links, addressToNumberConverter, unicodeSymbolMarker); var originalCharacter = 'H'; var characterLink = charToUnicodeSymbolConverter.Convert(originalCharacter); var unicodeSymbolCriterionMatcher = new TargetMatcher <ulong>(links, unicodeSymbolMarker); var unicodeSymbolToCharConverter = new UnicodeSymbolToCharConverter <ulong>(links, numberToAddressConverter, unicodeSymbolCriterionMatcher); var resultingCharacter = unicodeSymbolToCharConverter.Convert(characterLink); Assert.Equal(originalCharacter, resultingCharacter); }
public static TLink UpdateOrCreateOrGet <TLink>(this ILinks <TLink> links, TLink source, TLink target, TLink newSource, TLink newTarget) { var equalityComparer = EqualityComparer <TLink> .Default; var link = links.SearchOrDefault(source, target); if (equalityComparer.Equals(link, default)) { return(links.CreateAndUpdate(newSource, newTarget)); } if (equalityComparer.Equals(newSource, source) && equalityComparer.Equals(newTarget, target)) { return(link); } return(links.Update(link, newSource, newTarget)); }
private TLinkAddress GetOrCreateNextMapping(TLinkAddress currentMappingIndex) => _links.Exists(currentMappingIndex) ? currentMappingIndex : _links.CreateAndUpdate(_meaningRoot, _links.Constants.Itself);
private static void SetSteps(ILinks<ulong> links, ulong[] digits) { // 0 links.CreateAndUpdate(digits[0], digits[4]); links.CreateAndUpdate(digits[0], digits[6]); // 1 links.CreateAndUpdate(digits[1], digits[6]); links.CreateAndUpdate(digits[1], digits[8]); // 2 links.CreateAndUpdate(digits[2], digits[7]); links.CreateAndUpdate(digits[2], digits[9]); // 3 links.CreateAndUpdate(digits[3], digits[4]); links.CreateAndUpdate(digits[3], digits[8]); // 4 links.CreateAndUpdate(digits[4], digits[0]); links.CreateAndUpdate(digits[4], digits[3]); links.CreateAndUpdate(digits[4], digits[9]); // 5 // 6 links.CreateAndUpdate(digits[6], digits[0]); links.CreateAndUpdate(digits[6], digits[1]); links.CreateAndUpdate(digits[6], digits[7]); // 7 links.CreateAndUpdate(digits[7], digits[2]); links.CreateAndUpdate(digits[7], digits[6]); // 8 links.CreateAndUpdate(digits[8], digits[1]); links.CreateAndUpdate(digits[8], digits[3]); // 9 links.CreateAndUpdate(digits[9], digits[2]); links.CreateAndUpdate(digits[9], digits[4]); }