Exemple #1
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void doWrite(BigEndianByteArrayBuffer key, BigEndianByteArrayBuffer value, State expectedNextState) throws java.io.IOException
        private void DoWrite(BigEndianByteArrayBuffer key, BigEndianByteArrayBuffer value, State expectedNextState)
        {
            this._keySize   = key.Size();
            this._valueSize = value.Size();
            Debug.Assert(key.AllZeroes(), "key should have been cleared by previous call");
            if (!Write(key, value))
            {
                if (_state != expectedNextState)
                {
                    _state = State.InError;
                    throw new System.InvalidOperationException("MetadataCollector stopped before " + expectedNextState + " reached.");
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// Finds the page that would contain the given key from the <seealso cref="pageCatalogue page catalogue"/>.
        /// </summary>
        /// <param name="key"> The key to look for. </param>
        /// <returns> {@code -1} if the key is not contained in any page,
        /// otherwise the id of the page that would contain the key is returned. </returns>
        internal static int FindPage(BigEndianByteArrayBuffer key, sbyte[] catalogue)
        {
            int max = catalogue.Length / (key.Size() * 2) - 1;
            int min = 0;

            for (int mid; min <= max;)
            {
                mid = min + (max - min) / 2;
                // look at the low mark for the page
                int cmp = compare(key.Buffer, catalogue, mid * key.Size() * 2);
                if (cmp == 0)
                {
                    // this page starts with the key
                    // the previous page might also contain mid the key
                    max = mid;
                }
                if (cmp > 0)
                {
                    // look at the high mark for the page
                    cmp = compare(key.Buffer, catalogue, mid * key.Size() * 2 + key.Size());
                    if (cmp <= 0)
                    {
                        return(mid);                  // the key is within the range of this page
                    }
                    else                              // look at pages after 'mid'
                    {
                        min = mid + 1;
                    }
                }
                else                         // look at pages before 'mid'
                {
                    max = mid - 1;
                }
            }
            return(min);              // the first page after the value that was smaller than the key (mid + 1, you know...)
        }
Exemple #3
0
        /// <param name="cursor"> the cursor for the page to search for the key in. </param>
        /// <param name="searchKey"> the key to search for. </param>
        /// <param name="key"> a buffer to write the key into. </param>
        /// <param name="value"> a buffer to write the value into. </param>
        /// <returns> the offset (in bytes within the given page) of the first entry with a key that is greater than or equal
        /// to the given key. </returns>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private int findByteOffset(org.neo4j.io.pagecache.PageCursor cursor, BigEndianByteArrayBuffer searchKey, BigEndianByteArrayBuffer key, BigEndianByteArrayBuffer value) throws java.io.IOException
        private int FindByteOffset(PageCursor cursor, BigEndianByteArrayBuffer searchKey, BigEndianByteArrayBuffer key, BigEndianByteArrayBuffer value)
        {
            int entrySize  = searchKey.Size() + value.Size();
            int last       = MaxPage(_file.pageSize(), entrySize, _totalEntries);
            int firstEntry = (cursor.CurrentPageId == 0) ? _headerEntries : 0;                 // skip header in first page
            int entryCount = _totalEntries % (_file.pageSize() / entrySize);

            // If the last page is full, 'entryCount' will be 0 at this point.
            if (cursor.CurrentPageId != last || entryCount == 0)
            {               // The current page is a full page (either because it has pages after it, or the last page is actually full).
                entryCount = _file.pageSize() / entrySize;
            }
            int entryOffset = FindEntryOffset(cursor, searchKey, key, value, firstEntry, entryCount - 1);

            return(entryOffset * entrySize);
        }
Exemple #4
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public void writeData(BigEndianByteArrayBuffer key, BigEndianByteArrayBuffer value) throws java.io.IOException
        public virtual void WriteData(BigEndianByteArrayBuffer key, BigEndianByteArrayBuffer value)
        {
            _state.data(this);
            Debug.Assert(key.Size() == _keySize);
            Debug.Assert(value.Size() == _valueSize);
            if (key.AllZeroes())
            {
                _state = State.InError;
                throw new System.ArgumentException("All-zero keys are not allowed.");
            }
            if (!Write(key, value))
            {
                _state = State.InError;
                throw new System.InvalidOperationException("MetadataCollector stopped on data field.");
            }
        }
Exemple #5
0
        /// <param name="cursor"> the cursor for the page to search for the key in. </param>
        /// <param name="searchKey"> the key to search for. </param>
        /// <param name="key"> a buffer to write the key into. </param>
        /// <param name="value"> a buffer to write the value into. </param>
        /// <param name="min"> the offset (in number of entries within the page) of the first entry in the page. </param>
        /// <param name="max"> the offset (in number of entries within the page) of the last entry in the page. </param>
        /// <returns> the offset (in number of entries within the page) of the first entry with a key that is greater than or
        /// equal to the given key. </returns>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: static int findEntryOffset(org.neo4j.io.pagecache.PageCursor cursor, BigEndianByteArrayBuffer searchKey, BigEndianByteArrayBuffer key, BigEndianByteArrayBuffer value, int min, int max) throws java.io.IOException
        internal static int FindEntryOffset(PageCursor cursor, BigEndianByteArrayBuffer searchKey, BigEndianByteArrayBuffer key, BigEndianByteArrayBuffer value, int min, int max)
        {
            int entrySize = key.Size() + value.Size();

            for (int mid; min <= max;)
            {
                mid = min + (max - min) / 2;
                ReadKeyValuePair(cursor, mid * entrySize, key, value);
                if (min == max)
                {
                    break;                              // break here instead of in the loop condition to ensure the right key is read
                }
                int cmp = compare(searchKey.Buffer, key.Buffer, 0);
                if (cmp > 0)                           // search key bigger than found key, continue after 'mid'
                {
                    min = mid + 1;
                }
                else                         // search key smaller (or equal to) than found key, continue before 'mid'
                {
                    max = mid;               // don't add, greater than are to be included...
                }
            }
            return(max);
        }