Exemplo n.º 1
0
        // ReSharper disable once UnusedMember.Global
        public static void DoSave(IWriterCtx ctx, IOrderedSet <TKey>?dictionary, int cfgId)
        {
            var writerCtx = (IDBWriterCtx)ctx;

            if (!(dictionary is ODBSet <TKey> goodDict))
            {
                var tr = writerCtx.GetTransaction();
                var id = tr.AllocateDictionaryId();
                goodDict = new ODBSet <TKey>(tr, (ODBDictionaryConfiguration)writerCtx.FindInstance(cfgId), id);
                if (dictionary != null)
                {
                    foreach (var pair in dictionary)
                    {
                        goodDict.Add(pair);
                    }
                }
            }
            ctx.Writer().WriteVUInt64(goodDict._id);
        }
Exemplo n.º 2
0
            public AdvancedEnumerator(ODBSet <TKey> owner, AdvancedEnumeratorParam <TKey> param)
            {
                _owner      = owner;
                _keyValueTr = _owner._keyValueTr;
                _ascending  = param.Order == EnumerationOrder.Ascending;
                _prevModificationCounter = _owner._modificationCounter;
                _prevProtectionCounter   = _keyValueTr.CursorMovedCounter;
                _keyValueTr.FindFirstKey(_owner._prefix);
                var  prefixIndex = _keyValueTr.GetKeyIndex();
                long startIndex;
                long endIndex;

                if (param.EndProposition == KeyProposition.Ignored)
                {
                    _keyValueTr.FindLastKey(_owner._prefix);
                    endIndex = _keyValueTr.GetKeyIndex() - prefixIndex - 1;
                }
                else
                {
                    var keyBytes = _owner.KeyToByteArray(param.End);
                    switch (_keyValueTr.Find(keyBytes, (uint)_owner._prefix.Length))
                    {
                    case FindResult.Exact:
                        endIndex = _keyValueTr.GetKeyIndex() - prefixIndex;
                        if (param.EndProposition == KeyProposition.Excluded)
                        {
                            endIndex--;
                        }

                        break;

                    case FindResult.Previous:
                        endIndex = _keyValueTr.GetKeyIndex() - prefixIndex;
                        break;

                    case FindResult.Next:
                        endIndex = _keyValueTr.GetKeyIndex() - prefixIndex - 1;
                        break;

                    case FindResult.NotFound:
                        endIndex = -1;
                        break;

                    default:
                        throw new ArgumentOutOfRangeException();
                    }
                }

                if (param.StartProposition == KeyProposition.Ignored)
                {
                    startIndex = 0;
                }
                else
                {
                    var keyBytes = _owner.KeyToByteArray(param.Start);
                    switch (_keyValueTr.Find(keyBytes, (uint)_owner._prefix.Length))
                    {
                    case FindResult.Exact:
                        startIndex = _keyValueTr.GetKeyIndex() - prefixIndex;
                        if (param.StartProposition == KeyProposition.Excluded)
                        {
                            startIndex++;
                        }

                        break;

                    case FindResult.Previous:
                        startIndex = _keyValueTr.GetKeyIndex() - prefixIndex + 1;
                        break;

                    case FindResult.Next:
                        startIndex = _keyValueTr.GetKeyIndex() - prefixIndex;
                        break;

                    case FindResult.NotFound:
                        startIndex = 0;
                        break;

                    default:
                        throw new ArgumentOutOfRangeException();
                    }
                }

                _count     = (uint)Math.Max(0, endIndex - startIndex + 1);
                _startPos  = (uint)(_ascending ? startIndex : endIndex);
                _pos       = 0;
                _seekState = SeekState.Undefined;
            }