<commit_before>/*
 *  Copyright (c) 2012-2013 Malhar, Inc.
 *  All Rights Reserved.
 */
package com.malhartech.bufferserver.internal;

import com.malhartech.bufferserver.packet.BeginWindowTuple;
import com.malhartech.bufferserver.packet.MessageType;
import com.malhartech.bufferserver.packet.ResetWindowTuple;
import com.malhartech.bufferserver.packet.Tuple;
import com.malhartech.bufferserver.util.Codec;
import com.malhartech.bufferserver.util.Codec.MutableInt;
import com.malhartech.bufferserver.util.SerializedData;
import java.util.Arrays;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 *
 * @author <NAME> <<EMAIL>>
 */
public class Block
{
  /**
   * actual data - stored as length followed by actual data.
   */
  byte data[];
  /**
   * readingOffset is the offset of the first valid byte in the array.
   */
  int readingOffset;
  /**
   * writingOffset is the offset of the first available byte to write into.
   */
  int writingOffset;
  /**
   * The starting window which is available in this data array.
   */
  long starting_window = -1;
  /**
   * the ending window which is available in this data array
   */
  long ending_window;
  /**
   * when the data is null, uniqueIdentifier is the identifier in the backup storage to retrieve the object.
   */
  int uniqueIdentifier;
  /**
   * the next in the chain.
   */
  Block next;
  private int baseSeconds;
  private int intervalMillis;

  void getNextData(SerializedData current)
  {
    if (current.offset < writingOffset) {
      Codec.readRawVarInt32(current);
      if (current.offset + current.size >= writingOffset) {
        current.size = 0;
      }
    }
    else {
      current.size = 0;
    }
  }

  public void rewind(long windowId)
  {
    long bs = starting_window & 0x7fffffff00000000L;
    DataListIterator dli = new DataListIterator(this);
    done:
    while (dli.hasNext()) {
      SerializedData sd = dli.next();
      switch (sd.bytes[sd.dataOffset]) {
        case MessageType.RESET_WINDOW_VALUE:
          ResetWindowTuple rwt = (ResetWindowTuple)Tuple.getTuple(sd.bytes, sd.dataOffset, sd.size - sd.dataOffset + sd.offset);
          bs = (long)rwt.getBaseSeconds() << 32;
          if (bs > windowId) {
            writingOffset = sd.offset;
            break done;
          }
          break;

        case MessageType.BEGIN_WINDOW_VALUE:
          BeginWindowTuple bwt = (BeginWindowTuple)Tuple.getTuple(sd.bytes, sd.dataOffset, sd.size - sd.dataOffset + sd.offset);
          if ((bs | bwt.getWindowId()) >= windowId) {
            writingOffset = sd.offset;
            break done;
          }
          break;
      }
    }
  }

  public void purge(long longWindowId)
  {
    logger.debug("starting_window = {}, longWindowId = {}, baseSeconds = {}", new Object[] {Codec.getStringWindowId(this.starting_window), Codec.getStringWindowId(longWindowId), this.baseSeconds});
    boolean found = false;
    long bs = (long)this.baseSeconds << 32;<commit_msg>return the baseSeconds associated with the rewound block.<commit_after>/*
 *  Copyright (c) 2012-2013 Malhar, Inc.
 *  All Rights Reserved.
 */
package com.malhartech.bufferserver.internal;

import com.malhartech.bufferserver.packet.BeginWindowTuple;
import com.malhartech.bufferserver.packet.MessageType;
import com.malhartech.bufferserver.packet.ResetWindowTuple;
import com.malhartech.bufferserver.packet.Tuple;
import com.malhartech.bufferserver.util.Codec;
import com.malhartech.bufferserver.util.Codec.MutableInt;
import com.malhartech.bufferserver.util.SerializedData;
import java.util.Arrays;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 *
 * @author <NAME> <<EMAIL>>
 */
public class Block
{
  /**
   * actual data - stored as length followed by actual data.
   */
  byte data[];
  /**
   * readingOffset is the offset of the first valid byte in the array.
   */
  int readingOffset;
  /**
   * writingOffset is the offset of the first available byte to write into.
   */
  int writingOffset;
  /**
   * The starting window which is available in this data array.
   */
  long starting_window = -1;
  /**
   * the ending window which is available in this data array
   */
  long ending_window;
  /**
   * when the data is null, uniqueIdentifier is the identifier in the backup storage to retrieve the object.
   */
  int uniqueIdentifier;
  /**
   * the next in the chain.
   */
  Block next;
  private int baseSeconds;
  private int intervalMillis;

  void getNextData(SerializedData current)
  {
    if (current.offset < writingOffset) {
      Codec.readRawVarInt32(current);
      if (current.offset + current.size >= writingOffset) {
        current.size = 0;
      }
    }
    else {
      current.size = 0;
    }
  }

  public long rewind(long windowId)
  {
    long bs = starting_window & 0x7fffffff00000000L;
    DataListIterator dli = new DataListIterator(this);
    done:
    while (dli.hasNext()) {
      SerializedData sd = dli.next();
      switch (sd.bytes[sd.dataOffset]) {
        case MessageType.RESET_WINDOW_VALUE:
          ResetWindowTuple rwt = (ResetWindowTuple)Tuple.getTuple(sd.bytes, sd.dataOffset, sd.size - sd.dataOffset + sd.offset);
          bs = (long)rwt.getBaseSeconds() << 32;
          if (bs > windowId) {
            writingOffset = sd.offset;
            break done;
          }
          break;

        case MessageType.BEGIN_WINDOW_VALUE:
          BeginWindowTuple bwt = (BeginWindowTuple)Tuple.getTuple(sd.bytes, sd.dataOffset, sd.size - sd.dataOffset + sd.offset);
          if ((bs | bwt.getWindowId()) >= windowId) {
            writingOffset = sd.offset;
            break done;
          }
          break;
      }
    }

    return bs;
  }

  public void purge(long longWindowId)
  {
    logger.debug("starting_window = {}, longWindowId = {}, baseSeconds = {}", new Object[] {Codec.getStringWindowId(this.starting_window), Codec.getStringWindowId(longWindowId), this.baseSeconds});
    boolean found = false;
    long bs = (long)this.baseSeconds << 32;
{'fraction_non_alphanumeric': 0.10740493662441628, 'fraction_numerical': 0.009673115410273516, 'mean_word_length': 2.8790426908150066, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 4, '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': '7061533', 'n_tokens_mistral': 1898, 'n_tokens_neox': 1824, 'n_words': 460}