<commit_before>/**
 * @license
 * Copyright 2017 The FOAM Authors. All Rights Reserved.
 * http://www.apache.org/licenses/LICENSE-2.0
 */

package foam.dao.index;

public class LRUCachingIndex
    extends ProxyIndex
{
  protected int size_ = 0;
  protected final int maxSize_;

  protected LRUCachingState head_ = new LRUCachingState();
  protected LRUCachingState tail_ = new LRUCachingState();

  public LRUCachingIndex(int maxSize, Index index) {
    setDelegate(index);
    this.head_.setNext(tail_);
    this.tail_.setPrev(head_);
    this.maxSize_ = maxSize;
  }

  @Override
  public Object wrap(Object state) {
    LRUCachingState cache = new LRUCachingState(getDelegate().wrap(state), state);
    cache.setNext(head_.getNext());
    cache.setPrev(head_);
    head_.setNext(cache);

    size_ += 1;
    // remove oldest entry
    if ( size_ >= maxSize_ ) {
      LRUCachingState toRemove = tail_.getPrev();
      LRUCachingState prev = toRemove.getPrev();
      prev.setNext(tail_);
      tail_.setPrev(prev);
      toRemove.setValue(null);
      size_ -= 1;
    }

    return cache;
  }

  public Object unwrap(Object state) {
    LRUCachingState cache = (LRUCachingState) state;
    if ( cache.getValue() == null ) {
      cache.setValue(getDelegate().unwrap(cache.getKey()));
    }

    // get previous node of cached node
    // set the next node of the previous node
    // to the next node of the cached node
    LRUCachingState prev = cache.getPrev();
    prev.setNext(cache.getNext());

    // get next node of cached node
    // set the prev node of the next node
    // to the prev node of the cached node
    LRUCachingState next = cache.getNext();
    next.setPrev(cache.getPrev());

    // set cached node to be head
    cache.setPrev(head_);<commit_msg>Added setting of cache next value<commit_after>/**
 * @license
 * Copyright 2017 The FOAM Authors. All Rights Reserved.
 * http://www.apache.org/licenses/LICENSE-2.0
 */

package foam.dao.index;

public class LRUCachingIndex
    extends ProxyIndex
{
  protected int size_ = 0;
  protected final int maxSize_;

  protected LRUCachingState head_ = new LRUCachingState();
  protected LRUCachingState tail_ = new LRUCachingState();

  public LRUCachingIndex(int maxSize, Index index) {
    setDelegate(index);
    this.head_.setNext(tail_);
    this.tail_.setPrev(head_);
    this.maxSize_ = maxSize;
  }

  @Override
  public Object wrap(Object state) {
    LRUCachingState cache = new LRUCachingState(getDelegate().wrap(state), state);
    cache.setNext(head_.getNext());
    cache.setPrev(head_);
    head_.setNext(cache);

    size_ += 1;
    // remove oldest entry
    if ( size_ >= maxSize_ ) {
      LRUCachingState toRemove = tail_.getPrev();
      LRUCachingState prev = toRemove.getPrev();
      prev.setNext(tail_);
      tail_.setPrev(prev);
      toRemove.setValue(null);
      size_ -= 1;
    }

    return cache;
  }

  public Object unwrap(Object state) {
    LRUCachingState cache = (LRUCachingState) state;
    if ( cache.getValue() == null ) {
      cache.setValue(getDelegate().unwrap(cache.getKey()));
    }

    // get previous node of cached node
    // set the next node of the previous node
    // to the next node of the cached node
    LRUCachingState prev = cache.getPrev();
    prev.setNext(cache.getNext());

    // get next node of cached node
    // set the prev node of the next node
    // to the prev node of the cached node
    LRUCachingState next = cache.getNext();
    next.setPrev(cache.getPrev());

    // set cached node to be head
    cache.setPrev(head_);
    cache.setNext(head_.getNext());
{'fraction_non_alphanumeric': 0.11064891846921797, 'fraction_numerical': 0.004991680532445923, 'mean_word_length': 3.0391937290033595, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6257404', 'n_tokens_mistral': 1138, 'n_tokens_neox': 1089, 'n_words': 307}