protected UInt32InternalLinksRecursionlessSizeBalancedTreeMethodsBase(LinksConstants <TLink> constants, RawLinkDataPart <TLink> *linksDataParts, RawLinkIndexPart <TLink> *linksIndexParts, LinksHeader <TLink> *header)
     : base(constants, (byte *)linksDataParts, (byte *)linksIndexParts, (byte *)header)
 {
     LinksDataParts  = linksDataParts;
     LinksIndexParts = linksIndexParts;
     Header          = header;
 }
示例#2
0
        public static void ConstructorTest()
        {
            var constants = new LinksConstants <ulong>(enableExternalReferencesSupport: true);

            Assert.Equal(Hybrid <ulong> .ExternalZero, constants.ExternalReferencesRange.Value.Minimum);
            Assert.Equal(ulong.MaxValue, constants.ExternalReferencesRange.Value.Maximum);
        }
 public InternalLinksSourcesLinkedListMethods(LinksConstants <TLink> constants, byte *linksDataParts, byte *linksIndexParts)
 {
     _linksDataParts  = linksDataParts;
     _linksIndexParts = linksIndexParts;
     Break            = constants.Break;
     Continue         = constants.Continue;
 }
示例#4
0
        /// <summary>
        /// <para>
        /// Initializes a new <see cref="FileStorage"/> instance.
        /// </para>
        /// <para></para>
        /// </summary>
        /// <param name="DBFilename">
        /// <para>A db filename.</para>
        /// <para></para>
        /// </param>
        public FileStorage(string DBFilename)
        {
            var linksConstants = new LinksConstants <TLinkAddress>(enableExternalReferencesSupport: true);
            var dataMemory     = new FileMappedResizableDirectMemory(DBFilename);

            _disposableLinks   = new UnitedMemoryLinks <TLinkAddress>(dataMemory, UnitedMemoryLinks <UInt64> .DefaultLinksSizeStep, linksConstants, IndexTreeType.Default);
            _synchronizedLinks = new SynchronizedLinks <TLinkAddress>(_disposableLinks);
            var link = _synchronizedLinks.Create();

            link = _synchronizedLinks.Update(link, newSource: link, newTarget: link);
            ushort currentMappingLinkIndex = 1;

            Any                       = _synchronizedLinks.Constants.Any;
            _meaningRoot              = GetOrCreateMeaningRoot(currentMappingLinkIndex++);
            _unicodeSymbolMarker      = GetOrCreateNextMapping(currentMappingLinkIndex++);
            _unicodeSequenceMarker    = GetOrCreateNextMapping(currentMappingLinkIndex++);
            _setMarker                = GetOrCreateNextMapping(currentMappingLinkIndex++);
            _fileMarker               = GetOrCreateNextMapping(currentMappingLinkIndex++);
            _addressToNumberConverter = new AddressToRawNumberConverter <TLinkAddress>();
            _numberToAddressConverter = new RawNumberToAddressConverter <TLinkAddress>();
            var balancedVariantConverter        = new BalancedVariantConverter <TLinkAddress>(_synchronizedLinks);
            var unicodeSymbolCriterionMatcher   = new TargetMatcher <TLinkAddress>(_synchronizedLinks, _unicodeSymbolMarker);
            var unicodeSequenceCriterionMatcher = new TargetMatcher <TLinkAddress>(_synchronizedLinks, _unicodeSequenceMarker);
            var charToUnicodeSymbolConverter    = new CharToUnicodeSymbolConverter <TLinkAddress>(_synchronizedLinks, _addressToNumberConverter, _unicodeSymbolMarker);
            var unicodeSymbolToCharConverter    = new UnicodeSymbolToCharConverter <TLinkAddress>(_synchronizedLinks, _numberToAddressConverter, unicodeSymbolCriterionMatcher);
            var sequenceWalker = new RightSequenceWalker <TLinkAddress>(_synchronizedLinks, new DefaultStack <TLinkAddress>(), unicodeSymbolCriterionMatcher.IsMatched);

            _stringToUnicodeSequenceConverter = new CachingConverterDecorator <string, TLinkAddress>(new StringToUnicodeSequenceConverter <TLinkAddress>(_synchronizedLinks, charToUnicodeSymbolConverter, balancedVariantConverter, _unicodeSequenceMarker));
            _unicodeSequenceToStringConverter = new CachingConverterDecorator <TLinkAddress, string>(new UnicodeSequenceToStringConverter <TLinkAddress>(_synchronizedLinks, unicodeSequenceCriterionMatcher, sequenceWalker, unicodeSymbolToCharConverter));
        }
示例#5
0
 protected LinksRecursionlessSizeBalancedTreeMethodsBase(LinksConstants <TLink> constants, byte *links, byte *header)
 {
     Links    = links;
     Header   = header;
     Break    = constants.Break;
     Continue = constants.Continue;
 }
 protected InternalLinksRecursionlessSizeBalancedTreeMethodsBase(LinksConstants <TLink> constants, byte *linksDataParts, byte *linksIndexParts, byte *header)
 {
     LinksDataParts  = linksDataParts;
     LinksIndexParts = linksIndexParts;
     Header          = header;
     Break           = constants.Break;
     Continue        = constants.Continue;
 }
示例#7
0
 public Sequences(SynchronizedLinks <LinkIndex> links, SequencesOptions <LinkIndex> options)
 {
     Links   = links;
     _sync   = links.SyncRoot;
     Options = options;
     Options.ValidateOptions();
     Options.InitOptions(Links);
     Constants = links.Constants;
 }
示例#8
0
        private static void UsingWithExternalReferences <TLink>(Action <ILinks <TLink> > action)
        {
            var contants = new LinksConstants <TLink>(enableExternalReferencesSupport: true);

            using (var dataMemory = new HeapResizableDirectMemory())
                using (var indexMemory = new HeapResizableDirectMemory())
                    using (var memory = new SplitMemoryLinks <TLink>(dataMemory, indexMemory, SplitMemoryLinks <TLink> .DefaultLinksSizeStep, contants))
                    {
                        action(memory);
                    }
        }
        public ObjectsAndTagsStorage(string path, long minimumStorageSizeInBytes)
        {
            var constants = new LinksConstants <uint>(enableExternalReferencesSupport: true);

            _memory        = new FileMappedResizableDirectMemory(path);
            _memoryManager = new ResizableDirectMemoryLinks <uint>(_memory, minimumStorageSizeInBytes, constants, useAvlBasedIndex: false);

            _links = _memoryManager.DecorateWithAutomaticUniquenessAndUsagesResolution();
            _links = new LinksItselfConstantToSelfReferenceResolver <uint>(_links);

            _addressToRawNumberConverter = new AddressToRawNumberConverter <uint>();
        }
示例#10
0
        public DoubletsDbContext(string dataDBFilename, string indexDBFilename)
        {
            var dataMemory  = new FileMappedResizableDirectMemory(dataDBFilename);
            var indexMemory = new FileMappedResizableDirectMemory(indexDBFilename);

            var linksConstants = new LinksConstants <TLinkAddress>(enableExternalReferencesSupport: true);

            // Init the links storage
            _disposableLinks = new UInt32SplitMemoryLinks(dataMemory, indexMemory, UInt32SplitMemoryLinks.DefaultLinksSizeStep, linksConstants); // Low-level logic
            _links           = new UInt32Links(_disposableLinks);                                                                                // Main logic in the combined decorator

            // Set up constant links (markers, aka mapped links)
            TLinkAddress currentMappingLinkIndex = 1;

            _meaningRoot                       = GetOrCreateMeaningRoot(currentMappingLinkIndex++);
            _unicodeSymbolMarker               = GetOrCreateNextMapping(currentMappingLinkIndex++);
            _unicodeSequenceMarker             = GetOrCreateNextMapping(currentMappingLinkIndex++);
            _titlePropertyMarker               = GetOrCreateNextMapping(currentMappingLinkIndex++);
            _contentPropertyMarker             = GetOrCreateNextMapping(currentMappingLinkIndex++);
            _publicationDateTimePropertyMarker = GetOrCreateNextMapping(currentMappingLinkIndex++);
            _blogPostMarker                    = GetOrCreateNextMapping(currentMappingLinkIndex++);

            // Create properties operator that is able to control reading and writing properties for any link (object)
            _defaultLinkPropertyOperator = new PropertiesOperator <TLinkAddress>(_links);

            // Create converters that are able to convert link's address (UInt64 value) to a raw number represented with another UInt64 value and back
            _numberToAddressConverter = new RawNumberToAddressConverter <TLinkAddress>();
            _addressToNumberConverter = new AddressToRawNumberConverter <TLinkAddress>();

            // Create converters for dates
            _longRawNumberToDateTimeConverter = new LongRawNumberSequenceToDateTimeConverter <TLinkAddress>(new LongRawNumberSequenceToNumberConverter <TLinkAddress, long>(_links, _numberToAddressConverter));
            _dateTimeToLongRawNumberConverter = new DateTimeToLongRawNumberSequenceConverter <TLinkAddress>(new NumberToLongRawNumberSequenceConverter <long, TLinkAddress>(_links, _addressToNumberConverter));

            // Create converters that are able to convert string to unicode sequence stored as link and back
            var balancedVariantConverter        = new BalancedVariantConverter <TLinkAddress>(_links);
            var unicodeSymbolCriterionMatcher   = new TargetMatcher <TLinkAddress>(_links, _unicodeSymbolMarker);
            var unicodeSequenceCriterionMatcher = new TargetMatcher <TLinkAddress>(_links, _unicodeSequenceMarker);
            var charToUnicodeSymbolConverter    = new CharToUnicodeSymbolConverter <TLinkAddress>(_links, _addressToNumberConverter, _unicodeSymbolMarker);
            var unicodeSymbolToCharConverter    = new UnicodeSymbolToCharConverter <TLinkAddress>(_links, _numberToAddressConverter, unicodeSymbolCriterionMatcher);
            var sequenceWalker = new RightSequenceWalker <TLinkAddress>(_links, new DefaultStack <TLinkAddress>(), unicodeSymbolCriterionMatcher.IsMatched);

            _stringToUnicodeSequenceConverter = new CachingConverterDecorator <string, TLinkAddress>(new StringToUnicodeSequenceConverter <TLinkAddress>(_links, charToUnicodeSymbolConverter, balancedVariantConverter, _unicodeSequenceMarker));
            _unicodeSequenceToStringConverter = new CachingConverterDecorator <TLinkAddress, string>(new UnicodeSequenceToStringConverter <TLinkAddress>(_links, unicodeSequenceCriterionMatcher, sequenceWalker, unicodeSymbolToCharConverter));
        }
示例#11
0
        public Patterns(string sourceImagePath)
        {
            _sourceImagePath = Path.GetFullPath(sourceImagePath);
            _image           = new MagickImage(sourceImagePath);
            _pixels          = _image.GetPixels();
            _linksPath       = Path.ChangeExtension(_sourceImagePath, ".links");
            var memory    = new HeapResizableDirectMemory(); //new FileMappedResizableDirectMemory(_linksPath);
            var constants = new LinksConstants <ulong>(enableExternalReferencesSupport: true);

            _links = new UInt64Links(new UInt64UnitedMemoryLinks(memory, UInt64UnitedMemoryLinks.DefaultLinksSizeStep, constants, Platform.Data.Doublets.Memory.IndexTreeType.SizedAndThreadedAVLBalancedTree));
            _addressToRawNumberConverter         = new AddressToRawNumberConverter <ulong>();
            _rawNumberToAddressConverter         = new RawNumberToAddressConverter <ulong>();
            _totalSequenceSymbolFrequencyCounter = new TotalSequenceSymbolFrequencyCounter <ulong>(_links);
            _linkFrequenciesCache = new LinkFrequenciesCache <ulong>(_links, _totalSequenceSymbolFrequencyCounter);
            _index = new CachedFrequencyIncrementingSequenceIndex <ulong>(_linkFrequenciesCache);
            _linkToItsFrequencyNumberConverter        = new FrequenciesCacheBasedLinkToItsFrequencyNumberConverter <ulong>(_linkFrequenciesCache);
            _sequenceToItsLocalElementLevelsConverter = new SequenceToItsLocalElementLevelsConverter <ulong>(_links, _linkToItsFrequencyNumberConverter);
            _optimalVariantConverter = new OptimalVariantConverter <ulong>(_links, _sequenceToItsLocalElementLevelsConverter);
        }
示例#12
0
        private static void AppendPattern(ILinks <ulong> links, LinksConstants <ulong> constants, ulong start, ulong patternMarker, Dictionary <ulong, char> chars, ulong any, ulong @continue, StringBuilder sb, ulong initialPosition, RawNumberToAddressConverter <ulong> rawNumberToAddressConverter)
        {
            sb.Append('(');
            var alternatives = 0;

            links.Each(linkParts =>
            {
                var link = new UInt64Link(linkParts);
                if (patternMarker == link.Target)
                {
                    if (alternatives > 0)
                    {
                        sb.Append('|');
                    }
                    alternatives++;
                }
                else if (!constants.IsExternalReference(link.Target))
                {
                    var charPosition = new UInt64Link(links.GetLink(link.Target));
                    if (constants.IsExternalReference(charPosition.Source) && chars.TryGetValue(charPosition.Target, out char targetSymbol))
                    {
                        var position = rawNumberToAddressConverter.Convert(charPosition.Source) - 10;
                        if (position == initialPosition)
                        {
                            if (alternatives > 0)
                            {
                                sb.Append('|');
                            }
                            sb.Append(targetSymbol);
                            AppendPattern(links, constants, link.Target, patternMarker, chars, any, @continue, sb, initialPosition + 1, rawNumberToAddressConverter);
                            alternatives++;
                        }
                    }
                }
                return(@continue);
            }, new UInt64Link(any, start, any));
            sb.Append(')');
        }
示例#13
0
 private static string LinkToString(ILinks <ulong> links, LinksConstants <ulong> constants, ulong linkAddress, Dictionary <ulong, char> chars, RawNumberToAddressConverter <ulong> rawNumberToAddressConverter)
 {
     if (chars.TryGetValue(linkAddress, out char @char))
     {
         return($"'{@char.ToString()}'");
     }
     else if (constants.IsExternalReference(linkAddress))
     {
         return(rawNumberToAddressConverter.Convert(linkAddress).ToString());
     }
     else
     {
         var link = new UInt64Link(links.GetLink(linkAddress));
         if (constants.IsExternalReference(link.Source) && chars.TryGetValue(link.Target, out char targetChar))
         {
             return($"[{rawNumberToAddressConverter.Convert(link.Source)}]'{targetChar}'");
         }
         else
         {
             return(linkAddress.ToString());
         }
     }
 }
示例#14
0
        public PlatformDataBase(string indexFileName, string dataFileName)
        {
            this.indexFileName = indexFileName;
            this.dataFileName  = dataFileName;

            var dataMemory  = new FileMappedResizableDirectMemory(this.dataFileName);
            var indexMemory = new FileMappedResizableDirectMemory(this.indexFileName);

            var linksConstants = new LinksConstants <TLinkAddress>(enableExternalReferencesSupport: true);

            // Init the links storage
            this._disposableLinks = new UInt32SplitMemoryLinks(dataMemory, indexMemory, UInt32SplitMemoryLinks.DefaultLinksSizeStep, linksConstants); // Low-level logic
            this.links            = new UInt32Links(_disposableLinks);                                                                                // Main logic in the combined decorator

            // Set up constant links (markers, aka mapped links)
            TLinkAddress currentMappingLinkIndex = 1;

            this._meaningRoot           = GerOrCreateMeaningRoot(currentMappingLinkIndex++);
            this._unicodeSymbolMarker   = GetOrCreateNextMapping(currentMappingLinkIndex++);
            this._unicodeSequenceMarker = GetOrCreateNextMapping(currentMappingLinkIndex++);
            this._bookMarker            = GetOrCreateNextMapping(currentMappingLinkIndex++);
            // Create converters that are able to convert link's address (UInt64 value) to a raw number represented with another UInt64 value and back
            this._numberToAddressConverter = new RawNumberToAddressConverter <TLinkAddress>();
            this._addressToNumberConverter = new AddressToRawNumberConverter <TLinkAddress>();

            // Create converters that are able to convert string to unicode sequence stored as link and back
            var balancedVariantConverter        = new BalancedVariantConverter <TLinkAddress>(links);
            var unicodeSymbolCriterionMatcher   = new TargetMatcher <TLinkAddress>(links, _unicodeSymbolMarker);
            var unicodeSequenceCriterionMatcher = new TargetMatcher <TLinkAddress>(links, _unicodeSequenceMarker);
            var charToUnicodeSymbolConverter    = new CharToUnicodeSymbolConverter <TLinkAddress>(links, _addressToNumberConverter, _unicodeSymbolMarker);
            var unicodeSymbolToCharConverter    = new UnicodeSymbolToCharConverter <TLinkAddress>(links, _numberToAddressConverter, unicodeSymbolCriterionMatcher);
            var sequenceWalker = new RightSequenceWalker <TLinkAddress>(links, new DefaultStack <TLinkAddress>(), unicodeSymbolCriterionMatcher.IsMatched);

            this._stringToUnicodeSequenceConverter = new CachingConverterDecorator <string, TLinkAddress>(new StringToUnicodeSequenceConverter <TLinkAddress>(links, charToUnicodeSymbolConverter, balancedVariantConverter, _unicodeSequenceMarker));
            this._unicodeSequenceToStringConverter = new CachingConverterDecorator <TLinkAddress, string>(new UnicodeSequenceToStringConverter <TLinkAddress>(links, unicodeSequenceCriterionMatcher, sequenceWalker, unicodeSymbolToCharConverter));
        }
 public UInt64UnitedMemoryLinks(IResizableDirectMemory memory, long memoryReservationStep, LinksConstants <ulong> constants, IndexTreeType indexTreeType) : base(memory, memoryReservationStep, constants)
 {
     if (indexTreeType == IndexTreeType.SizedAndThreadedAVLBalancedTree)
     {
         _createSourceTreeMethods = () => new UInt64LinksSourcesAvlBalancedTreeMethods(Constants, _links, _header);
         _createTargetTreeMethods = () => new UInt64LinksTargetsAvlBalancedTreeMethods(Constants, _links, _header);
     }
     else if (indexTreeType == IndexTreeType.SizeBalancedTree)
     {
         _createSourceTreeMethods = () => new UInt64LinksSourcesSizeBalancedTreeMethods(Constants, _links, _header);
         _createTargetTreeMethods = () => new UInt64LinksTargetsSizeBalancedTreeMethods(Constants, _links, _header);
     }
     else
     {
         _createSourceTreeMethods = () => new UInt64LinksSourcesRecursionlessSizeBalancedTreeMethods(Constants, _links, _header);
         _createTargetTreeMethods = () => new UInt64LinksTargetsRecursionlessSizeBalancedTreeMethods(Constants, _links, _header);
     }
     Init(memory, memoryReservationStep);
 }
示例#16
0
 public ExternalLinksSourcesSizeBalancedTreeMethods(LinksConstants <TLink> constants, byte *linksDataParts, byte *linksIndexParts, byte *header) : base(constants, linksDataParts, linksIndexParts, header)
 {
 }
示例#17
0
 protected UInt64LinksAvlBalancedTreeMethodsBase(LinksConstants <ulong> constants, RawLink <ulong> *links, LinksHeader <ulong> *header)
     : base(constants, (byte *)links, (byte *)header)
 {
     Links  = links;
     Header = header;
 }
示例#18
0
        public static ILinks <TLinkAddress> CreateLinks <TLinkAddress>(string dataDbFilename)
        {
            var linksConstants = new LinksConstants <TLinkAddress>(enableExternalReferencesSupport: true);

            return(new UnitedMemoryLinks <TLinkAddress>(new FileMappedResizableDirectMemory(dataDbFilename), UnitedMemoryLinks <TLinkAddress> .DefaultLinksSizeStep, linksConstants, IndexTreeType.Default));
        }
 public UInt32SplitMemoryLinks(IResizableDirectMemory dataMemory, IResizableDirectMemory indexMemory, long memoryReservationStep, LinksConstants <TLink> constants, IndexTreeType indexTreeType, bool useLinkedList) : base(dataMemory, indexMemory, memoryReservationStep, constants, useLinkedList)
 {
     if (indexTreeType == IndexTreeType.SizeBalancedTree)
     {
         _createInternalSourceTreeMethods = () => new UInt32InternalLinksSourcesSizeBalancedTreeMethods(Constants, _linksDataParts, _linksIndexParts, _header);
         _createExternalSourceTreeMethods = () => new UInt32ExternalLinksSourcesSizeBalancedTreeMethods(Constants, _linksDataParts, _linksIndexParts, _header);
         _createInternalTargetTreeMethods = () => new UInt32InternalLinksTargetsSizeBalancedTreeMethods(Constants, _linksDataParts, _linksIndexParts, _header);
         _createExternalTargetTreeMethods = () => new UInt32ExternalLinksTargetsSizeBalancedTreeMethods(Constants, _linksDataParts, _linksIndexParts, _header);
     }
     else
     {
         _createInternalSourceTreeMethods = () => new UInt32InternalLinksSourcesRecursionlessSizeBalancedTreeMethods(Constants, _linksDataParts, _linksIndexParts, _header);
         _createExternalSourceTreeMethods = () => new UInt32ExternalLinksSourcesRecursionlessSizeBalancedTreeMethods(Constants, _linksDataParts, _linksIndexParts, _header);
         _createInternalTargetTreeMethods = () => new UInt32InternalLinksTargetsRecursionlessSizeBalancedTreeMethods(Constants, _linksDataParts, _linksIndexParts, _header);
         _createExternalTargetTreeMethods = () => new UInt32ExternalLinksTargetsRecursionlessSizeBalancedTreeMethods(Constants, _linksDataParts, _linksIndexParts, _header);
     }
     Init(dataMemory, indexMemory);
 }
示例#20
0
 public UInt32LinksTargetsSizeBalancedTreeMethods(LinksConstants <uint> constants, RawLink <uint> *links, LinksHeader <uint> *header) : base(constants, links, header)
 {
 }
示例#21
0
 public UInt32LinksSourcesRecursionlessSizeBalancedTreeMethods(LinksConstants <uint> constants, RawLink <uint> *links, LinksHeader <uint> *header) : base(constants, links, header)
 {
 }
示例#22
0
 public UInt64LinksSourcesSizeBalancedTreeMethods(LinksConstants <ulong> constants, RawLink <ulong> *links, LinksHeader <ulong> *header) : base(constants, links, header)
 {
 }
 public InternalLinksTargetsRecursionlessSizeBalancedTreeMethods(LinksConstants <TLink> constants, byte *linksDataParts, byte *linksIndexParts, byte *header) : base(constants, linksDataParts, linksIndexParts, header)
 {
 }
 public UInt32InternalLinksTargetsSizeBalancedTreeMethods(LinksConstants <TLink> constants, RawLinkDataPart <TLink> *linksDataParts, RawLinkIndexPart <TLink> *linksIndexParts, LinksHeader <TLink> *header) : base(constants, linksDataParts, linksIndexParts, header)
 {
 }
 public UInt64InternalLinksSourcesLinkedListMethods(LinksConstants<TLink> constants, RawLinkDataPart<TLink>* linksDataParts, RawLinkIndexPart<TLink>* linksIndexParts)
     : base(constants, (byte*)linksDataParts, (byte*)linksIndexParts)
 {
     _linksDataParts = linksDataParts;
     _linksIndexParts = linksIndexParts;
 }
示例#26
0
 public LinksSourcesAvlBalancedTreeMethods(LinksConstants <TLink> constants, byte *links, byte *header) : base(constants, links, header)
 {
 }
 public UInt32SplitMemoryLinks(IResizableDirectMemory dataMemory, IResizableDirectMemory indexMemory, long memoryReservationStep, LinksConstants <TLink> constants) : this(dataMemory, indexMemory, memoryReservationStep, constants, IndexTreeType.Default, useLinkedList : true)
 {
 }
 public UInt64InternalLinksSourcesRecursionlessSizeBalancedTreeMethods(LinksConstants <TLink> constants, RawLinkDataPart <TLink> *linksDataParts, RawLinkIndexPart <TLink> *linksIndexParts, LinksHeader <TLink> *header) : base(constants, linksDataParts, linksIndexParts, header)
 {
 }
示例#29
0
 public LinksSourcesRecursionlessSizeBalancedTreeMethods(LinksConstants <TLink> constants, byte *links, byte *header) : base(constants, links, header)
 {
 }
示例#30
0
 protected UInt32LinksRecursionlessSizeBalancedTreeMethodsBase(LinksConstants <uint> constants, RawLink <uint> *links, LinksHeader <uint> *header)
     : base(constants, (byte *)links, (byte *)header)
 {
     Links  = links;
     Header = header;
 }