<commit_before>/**
 * Copyright 2012 <NAME>
 * This project includes software developed by <NAME>: https://github.com/jeluard/
 *
 * 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.
 */
package com.github.jeluard.stone.storage.memory;

import com.github.jeluard.guayaba.base.Pair;
import com.github.jeluard.stone.spi.Storage;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.atomic.AtomicIntegerArray;
import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.atomic.AtomicLongArray;

/**
 * An in-memory {@link Storage} implementation.
 */
public final class MemoryStorage extends Storage {

  private final AtomicLong index = new AtomicLong(0);
  private final int nbValues;
  private final AtomicLongArray timestamps;
  private final AtomicIntegerArray values;

  public MemoryStorage(final int maximumSize) {
    super(maximumSize);

    this.nbValues = 1;//TODO
    this.timestamps = new AtomicLongArray(getMaximumSize());
    this.values = new AtomicIntegerArray(getMaximumSize()*nbValues);
  }

  @Override
  public Iterable<Pair<Long, int[]>> all() throws IOException {
    final int maxSize = getMaximumSize();
    final List<Pair<Long, int[]>> all = new ArrayList<Pair<Long, int[]>>(maxSize);
    for (int i = 0; i < maxSize; i++) {
      final long timestamp = this.timestamps.get(i);
      if (timestamp == 0L) {
        break;
      }
      final int[] consolidates = new int[this.nbValues];
      for (int j = 0; j < this.nbValues; j++) {
        consolidates[j] = this.values.get(i*this.nbValues+j);
      }
      all.add(new Pair<Long, int[]>(timestamp, consolidates));
    }
    return all;
  }

  private int index() {
    return (int) (this.index.getAndIncrement() % getMaximumSize());
  }

  @Override
  public void append(final long timestamp, final int[] values) {
    final int currentIndex = index();
    this.timestamps.set(currentIndex, timestamp);
    for (int i = 0; i < values.length; i++) {
      this.values.set(currentIndex + i, values[i]);
    }
  }

}<commit_msg>Fixed broken memory storage implementation.<commit_after>/**
 * Copyright 2012 <NAME>
 * This project includes software developed by <NAME>: https://github.com/jeluard/
 *
 * 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.
 */
package com.github.jeluard.stone.storage.memory;

import com.github.jeluard.guayaba.base.Pair;
import com.github.jeluard.stone.spi.Storage;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.atomic.AtomicLongArray;
import java.util.concurrent.atomic.AtomicReferenceArray;

/**
 * An in-memory {@link Storage} implementation.
 */
public final class MemoryStorage extends Storage {

  private final AtomicLong index = new AtomicLong(0);
  private final AtomicLongArray timestamps;
  private final AtomicReferenceArray<int[]> values;

  public MemoryStorage(final int maximumSize) {
    super(maximumSize);

    this.timestamps = new AtomicLongArray(getMaximumSize());
    this.values = new AtomicReferenceArray<int[]>(getMaximumSize());
  }

  @Override
  public Iterable<Pair<Long, int[]>> all() throws IOException {
    final int maxSize = getMaximumSize();
    final List<Pair<Long, int[]>> all = new ArrayList<Pair<Long, int[]>>(maxSize);
    for (int i = 0; i < maxSize; i++) {
      final long timestamp = this.timestamps.get(i);
      if (timestamp == 0L) {
        break;
      }

      all.add(new Pair<Long, int[]>(timestamp, this.values.get(i)));
    }
    return all;
  }

  private int index() {
    return (int) (this.index.getAndIncrement() % getMaximumSize());
  }

  @Override
  public void append(final long timestamp, final int[] values) {
    final int currentIndex = index();
    this.timestamps.set(currentIndex, timestamp);
    this.values.set(currentIndex, values);
  }

}
{'fraction_non_alphanumeric': 0.11437308868501529, 'fraction_numerical': 0.0050968399592252805, 'mean_word_length': 3.8767395626242545, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 23, 'https://': 2, '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': '539846', 'n_tokens_mistral': 1460, 'n_tokens_neox': 1405, 'n_words': 446}