Esempio n. 1
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));
        }
Esempio n. 2
0
        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);
        }
Esempio n. 3
0
        public static void StringAndUnicodeSequenceConvertersTest()
        {
            using (var scope = new TempLinksTestScope())
            {
                var links = scope.Links;

                var itself = links.Constants.Itself;

                var meaningRoot             = links.CreatePoint();
                var unaryOne                = links.CreateAndUpdate(meaningRoot, itself);
                var unicodeSymbolMarker     = links.CreateAndUpdate(meaningRoot, itself);
                var unicodeSequenceMarker   = links.CreateAndUpdate(meaningRoot, itself);
                var frequencyMarker         = links.CreateAndUpdate(meaningRoot, itself);
                var frequencyPropertyMarker = links.CreateAndUpdate(meaningRoot, itself);

                var powerOf2ToUnaryNumberConverter = new PowerOf2ToUnaryNumberConverter <ulong>(links, unaryOne);
                var addressToUnaryNumberConverter  = new AddressToUnaryNumberConverter <ulong>(links, powerOf2ToUnaryNumberConverter);
                var charToUnicodeSymbolConverter   = new CharToUnicodeSymbolConverter <ulong>(links, addressToUnaryNumberConverter, unicodeSymbolMarker);

                var unaryNumberToAddressConverter = new UnaryNumberToAddressOrOperationConverter <ulong>(links, powerOf2ToUnaryNumberConverter);
                var unaryNumberIncrementer        = new UnaryNumberIncrementer <ulong>(links, unaryOne);
                var frequencyIncrementer          = new FrequencyIncrementer <ulong>(links, frequencyMarker, unaryOne, unaryNumberIncrementer);
                var frequencyPropertyOperator     = new PropertyOperator <ulong>(links, frequencyPropertyMarker, frequencyMarker);
                var index = new FrequencyIncrementingSequenceIndex <ulong>(links, frequencyPropertyOperator, frequencyIncrementer);
                var linkToItsFrequencyNumberConverter        = new LinkToItsFrequencyNumberConveter <ulong>(links, frequencyPropertyOperator, unaryNumberToAddressConverter);
                var sequenceToItsLocalElementLevelsConverter = new SequenceToItsLocalElementLevelsConverter <ulong>(links, linkToItsFrequencyNumberConverter);
                var optimalVariantConverter = new OptimalVariantConverter <ulong>(links, sequenceToItsLocalElementLevelsConverter);

                var stringToUnicodeSequenceConverter = new StringToUnicodeSequenceConverter <ulong>(links, charToUnicodeSymbolConverter, index, optimalVariantConverter, unicodeSequenceMarker);

                var originalString = "Hello";

                var unicodeSequenceLink = stringToUnicodeSequenceConverter.Convert(originalString);

                var unicodeSymbolCriterionMatcher = new TargetMatcher <ulong>(links, unicodeSymbolMarker);
                var unicodeSymbolToCharConverter  = new UnicodeSymbolToCharConverter <ulong>(links, unaryNumberToAddressConverter, unicodeSymbolCriterionMatcher);

                var unicodeSequenceCriterionMatcher = new TargetMatcher <ulong>(links, unicodeSequenceMarker);

                var sequenceWalker = new LeveledSequenceWalker <ulong>(links, unicodeSymbolCriterionMatcher.IsMatched);

                var unicodeSequenceToStringConverter = new UnicodeSequenceToStringConverter <ulong>(links, unicodeSequenceCriterionMatcher, sequenceWalker, unicodeSymbolToCharConverter);

                var resultingString = unicodeSequenceToStringConverter.Convert(unicodeSequenceLink);

                Assert.Equal(originalString, resultingString);
            }
        }
Esempio n. 4
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));
        }
Esempio n. 5
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));
        }