<commit_before>module.exports =
class HistoryProvider

  constructor: (items) ->
    @set items

  set: (@items) ->
    @items ?= []
    @position = @items.length

  push: (x) ->
    if not @isEquiv(x, @items[@items.length-1])
      @items.push x
      @position = @items.length

  getPrevious: ->
    if @position > 0
      @position--
      @items[@position]

  getNext: ->
    if not @isAtEnd()
      @position++
    @items[@position] or input: ""

  isAtEnd: ->
    @position is @items.length

  isEquiv: (a, b) ->
    a.mode is b.mode and a.input is b.input<commit_msg>remove history cycles<commit_after>module.exports =
class HistoryProvider

  constructor: (items) ->
    @set items

  set: (@items) ->
    @items ?= []
    @position = @items.length

  push: (x) ->
    @items.push x
    @position = @items.length
    @removeCycles()

  getPrevious: ->
    if @position > 0
      @position--
      @items[@position]

  getNext: ->
    if not @isAtEnd()
      @position++
    @items[@position] or input: ""

  isAtEnd: ->
    @position is @items.length

  isEquiv: (a, b) ->
    a.mode is b.mode and a.input is b.input

  removeCycles: ->
    for n in [1..Math.min(@items.length/2, 100)]
      for i in [1..n]
        if @isEquiv @items[@items.length-i], @items[@items.length-(i+n)]
          if i is n # History items up to length n are duplicates
            @set @items.slice(0, @items.length - n)
            return
        else
          break
    return
{'fraction_non_alphanumeric': 0.15017064846416384, 'fraction_numerical': 0.006825938566552901, 'mean_word_length': 2.166306695464363, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 20, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '7119092', 'n_tokens_mistral': 519, 'n_tokens_neox': 494, 'n_words': 132}