<commit_before>////////////////////////////////////////////////////////////////////////////////
/// @brief skiplist index
///
/// @file
///
/// DISCLAIMER
///
/// Copyright 2014 ArangoDB GmbH, Cologne, Germany
/// Copyright 2004-2014 triAGENS GmbH, Cologne, Germany
///
/// Licensed under the Apache License, Version 2.0 (the "License");
/// you may not use this file except in compliance with the License.
/// You may obtain a copy of the License at
///
///     http://www.apache.org/licenses/LICENSE-2.0
///
/// Unless required by applicable law or agreed to in writing, software
/// distributed under the License is distributed on an "AS IS" BASIS,
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
/// See the License for the specific language governing permissions and
/// limitations under the License.
///
/// Copyright holder is ArangoDB GmbH, Cologne, Germany
///
/// @author Dr. <NAME>
/// @author Copyright 2014, ArangoDB GmbH, Cologne, Germany
/// @author Copyright 2011-2013, triAGENS GmbH, Cologne, Germany
////////////////////////////////////////////////////////////////////////////////

#ifndef ARANGODB_INDEXES_SKIPLIST_INDEX_H
#define ARANGODB_INDEXES_SKIPLIST_INDEX_H 1

#include "Basics/Common.h"
#include "Indexes/PathBasedIndex.h"
#include "Indexes/skiplist-helper.h"
#include "IndexOperators/index-operator.h"
#include "VocBase/shaped-json.h"
#include "VocBase/vocbase.h"
#include "VocBase/voc-types.h"

// -----------------------------------------------------------------------------
// --SECTION--                                               class SkiplistIndex
// -----------------------------------------------------------------------------

typedef struct {
  TRI_shaped_json_t* _fields;   // list of shaped json objects which the
                                // collection should know about
  size_t _numFields;   // Note that the number of fields coming from
                       // a query can be smaller than the number of
                       // fields indexed
}
TRI_skiplist_index_key_t;

namespace triagens {
  namespace arango {

////////////////////////////////////////////////////////////////////////////////
/// @brief Iterator structure for skip list. We require a start and stop node
///
/// Intervals are open in the sense that both end points are not members
/// of the interval. This means that one has to use SkipList::nextNode
/// on the start node to get the first element and that the stop node
/// can be NULL. Note that it is ensured that all intervals in an iterator
/// are non-empty.
////////////////////////////////////////////////////////////////////////////////

    class SkiplistIterator {
      private:

// -----------------------------------------------------------------------------
// --SECTION--                                                   private structs
// -----------------------------------------------------------------------------
        // Shorthand for the skiplist node
        typedef triagens::basics::SkipListNode<TRI_skiplist_index_key_t, TRI_index_element_t> Node;

        struct SkiplistIteratorInterval {
          Node* _leftEndPoint;
          Node* _rightEndPoint;
        };

// -----------------------------------------------------------------------------
// --SECTION--                                                 private variables
// -----------------------------------------------------------------------------
        SkiplistIndex2* const _index;
        size_t _currentInterval; // starts with 0, current interval used
        bool _reverse;
        Node* _cursor;

// -----------------------------------------------------------------------------
// --SECTION--                                                  public variables
// -----------------------------------------------------------------------------

      public:

        std::vector<SkiplistIteratorInterval*> _intervals;

      public:

// -----------------------------------------------------------------------------
// --SECTION--                                        constructors / destructors
// -----------------------------------------------------------------------------

        SkiplistIterator (
          SkiplistIndex2* const idx,
          bool reverse
        ) : _index(idx) ,
            _reverse(reverse) {
          _currentInterval = 0;
          _cursor = nullptr;
        };

        ~SkiplistIterator () {};

        // always holds the last node returned, initially equal to
        // the _leftEndPoint of the first interval (or the 
        // _rightEndPoint of the last interval in the reverse
        // case), can be nullptr if there are no intervals
        // (yet), or, in the reverse case, if the cursor is
        // at the end of the last interval. Additionally
        // in the non-reverse case _cursor is set to nullptr
        // if the cursor is exhausted.
        // See SkiplistNextIterationCallback and
        // SkiplistPrevIterationCallback for the exact
        // condition for the iterator to be exhausted.
        
// -----------------------------------------------------------------------------
// --SECTION--                                                    public methods
// -----------------------------------------------------------------------------
        
        size_t size ();

        bool hasNext ();

        TRI_index_element_t* next ();

        void initCursor ();

        void findHelper (
          TRI_index_operator_t const* indexOperator,
          std::vector<SkiplistIteratorInterval*>& intervals
        );
// -----------------------------------------------------------------------------
// --SECTION--                                                   private methods
// -----------------------------------------------------------------------------

      private:

        bool hasPrevIteration ();
        TRI_index_element_t* prevIteration ();<commit_msg>Properly initialized objects of SkiplistInterval<commit_after>////////////////////////////////////////////////////////////////////////////////
/// @brief skiplist index
///
/// @file
///
/// DISCLAIMER
///
/// Copyright 2014 ArangoDB GmbH, Cologne, Germany
/// Copyright 2004-2014 triAGENS GmbH, Cologne, Germany
///
/// Licensed under the Apache License, Version 2.0 (the "License");
/// you may not use this file except in compliance with the License.
/// You may obtain a copy of the License at
///
///     http://www.apache.org/licenses/LICENSE-2.0
///
/// Unless required by applicable law or agreed to in writing, software
/// distributed under the License is distributed on an "AS IS" BASIS,
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
/// See the License for the specific language governing permissions and
/// limitations under the License.
///
/// Copyright holder is ArangoDB GmbH, Cologne, Germany
///
/// @author Dr. <NAME>
/// @author Copyright 2014, ArangoDB GmbH, Cologne, Germany
/// @author Copyright 2011-2013, triAGENS GmbH, Cologne, Germany
////////////////////////////////////////////////////////////////////////////////

#ifndef ARANGODB_INDEXES_SKIPLIST_INDEX_H
#define ARANGODB_INDEXES_SKIPLIST_INDEX_H 1

#include "Basics/Common.h"
#include "Indexes/PathBasedIndex.h"
#include "Indexes/skiplist-helper.h"
#include "IndexOperators/index-operator.h"
#include "VocBase/shaped-json.h"
#include "VocBase/vocbase.h"
#include "VocBase/voc-types.h"

// -----------------------------------------------------------------------------
// --SECTION--                                               class SkiplistIndex
// -----------------------------------------------------------------------------

typedef struct {
  TRI_shaped_json_t* _fields;   // list of shaped json objects which the
                                // collection should know about
  size_t _numFields;   // Note that the number of fields coming from
                       // a query can be smaller than the number of
                       // fields indexed
}
TRI_skiplist_index_key_t;

namespace triagens {
  namespace arango {

////////////////////////////////////////////////////////////////////////////////
/// @brief Iterator structure for skip list. We require a start and stop node
///
/// Intervals are open in the sense that both end points are not members
/// of the interval. This means that one has to use SkipList::nextNode
/// on the start node to get the first element and that the stop node
/// can be NULL. Note that it is ensured that all intervals in an iterator
/// are non-empty.
////////////////////////////////////////////////////////////////////////////////

    class SkiplistIterator {
      private:
        friend class SkiplistIndex2;

// -----------------------------------------------------------------------------
// --SECTION--                                                   private structs
// -----------------------------------------------------------------------------
        // Shorthand for the skiplist node
        typedef triagens::basics::SkipListNode<TRI_skiplist_index_key_t, TRI_index_element_t> Node;

        struct SkiplistIteratorInterval {
          Node* _leftEndPoint;
          Node* _rightEndPoint;
        };

// -----------------------------------------------------------------------------
// --SECTION--                                                 private variables
// -----------------------------------------------------------------------------
        SkiplistIndex2* const _index;
        size_t _currentInterval; // starts with 0, current interval used
        bool _reverse;
        Node* _cursor;
        std::vector<SkiplistIteratorInterval*> _intervals;

      public:

// -----------------------------------------------------------------------------
// --SECTION--                                        constructors / destructors
// -----------------------------------------------------------------------------

        SkiplistIterator (
          SkiplistIndex2* const idx,
          bool reverse
        ) : _index(idx) ,
            _currentInterval(0),
            _reverse(reverse),
            _cursor(nullptr) {
        };

        ~SkiplistIterator () {};

        // always holds the last node returned, initially equal to
        // the _leftEndPoint of the first interval (or the 
        // _rightEndPoint of the last interval in the reverse
        // case), can be nullptr if there are no intervals
        // (yet), or, in the reverse case, if the cursor is
        // at the end of the last interval. Additionally
        // in the non-reverse case _cursor is set to nullptr
        // if the cursor is exhausted.
        // See SkiplistNextIterationCallback and
        // SkiplistPrevIterationCallback for the exact
        // condition for the iterator to be exhausted.
        
// -----------------------------------------------------------------------------
// --SECTION--                                                    public methods
// -----------------------------------------------------------------------------
        
        size_t size ();

        bool hasNext ();

        TRI_index_element_t* next ();

        void initCursor ();

        void findHelper (
          TRI_index_operator_t const* indexOperator,
          std::vector<SkiplistIteratorInterval*>& interval
        );
// -----------------------------------------------------------------------------
// --SECTION--                                                   private methods
// -----------------------------------------------------------------------------

      private:

        bool hasPrevIteration ();
        TRI_index_element_t* prevIteration ();
{'fraction_non_alphanumeric': 0.2956819153484395, 'fraction_numerical': 0.00572894399315947, 'mean_word_length': 1.0065191284954538, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 26, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7368858', 'n_tokens_mistral': 2494, 'n_tokens_neox': 2331, 'n_words': 837}