<commit_before>###
@description One possible way to store common recyclable objects.
Assumes the objects you add will have an `active` property, and optionally an
`activate()` method which resets the object's state. Inspired by Programming
Linux Games (http://en.wikipedia.org/wiki/Programming_Linux_Games)
###
class Pool
  constructor: ->
    @children = []
    @length = 0
    @tmp = null

    # Instantiate/return child objects using factory
    @factory = null

  at: (index) ->
    return null if index >= @length
    @children[index]

  ###
  @description Push an object into the recycle pool
  ###
  add: (object) ->
    @children.push object

    # Swap with inactive object
    if @length < @children.length
      @tmp = @children[@children.length - 1]
      @children[@children.length - 1] = @children[@length]
      @children[@length] = @tmp

    @length += 1
    @length

  ###
  @description Remove an object from the recycle pool
  ###
  remove: (objectOrIndex) ->
    throw 'Must specify an object/index to remove' if objectOrIndex is undefined

    index = if typeof objectOrIndex != 'number' then @children.indexOf objectOrIndex else objectOrIndex
    return if index is -1

    object = @children.splice(index, 1)[0]
    object.destroy() if typeof object.destroy is 'function'

    @length -= 1 if index < @length
    object

  ###
  @description Get an active object by either reference or index
  ###
  activate: (objectOrIndex) ->
    if objectOrIndex != undefined
      index = if typeof objectOrIndex != 'number' then @children.indexOf(objectOrIndex) else objectOrIndex

      # TODO: Spec this behavior
      return null unless @children.length > index >= @length

      @tmp = @children[@length]
      @children[@length] = @children[index]
      @children[index] = @tmp
      @tmp = null
      @length += 1
      return @children[@length - 1]

    if objectOrIndex == undefined && @length < @children.length
      @length += 1
      @children[@length - 1].reset() if typeof @children[@length - 1].reset == 'function'
      return @children[@length - 1]

    throw 'Pools need a factory function' if typeof @factory != 'function'

    @children.push @factory()
    @length += 1
    return @children[@length - 1]

  ###
  @description Deactivate an active object at a particular object/index
  ###
  deactivate: (objectOrIndex) ->
    index = if typeof objectOrIndex != 'number' then @children.indexOf(objectOrIndex) else objectOrIndex

    # TODO: Spec this behavior
    return null if index >= @length || index < 0
<commit_msg>Throw `Error` objects<commit_after>###
@description One possible way to store common recyclable objects.
Assumes the objects you add will have an `active` property, and optionally an
`activate()` method which resets the object's state. Inspired by Programming
Linux Games (http://en.wikipedia.org/wiki/Programming_Linux_Games)
###
class Pool
  constructor: ->
    @children = []
    @length = 0
    @tmp = null

    # Instantiate/return child objects using factory
    @factory = null

  at: (index) ->
    return null if index >= @length
    @children[index]

  ###
  @description Push an object into the recycle pool
  ###
  add: (object) ->
    @children.push object

    # Swap with inactive object
    if @length < @children.length
      @tmp = @children[@children.length - 1]
      @children[@children.length - 1] = @children[@length]
      @children[@length] = @tmp

    @length += 1
    @length

  ###
  @description Remove an object from the recycle pool
  ###
  remove: (objectOrIndex) ->
    throw new Error('Must specify an object/index to remove') if objectOrIndex is undefined

    index = if typeof objectOrIndex != 'number' then @children.indexOf objectOrIndex else objectOrIndex
    return if index is -1

    object = @children.splice(index, 1)[0]
    object.destroy() if typeof object.destroy is 'function'

    @length -= 1 if index < @length
    object

  ###
  @description Get an active object by either reference or index
  ###
  activate: (objectOrIndex) ->
    if objectOrIndex != undefined
      index = if typeof objectOrIndex != 'number' then @children.indexOf(objectOrIndex) else objectOrIndex

      # TODO: Spec this behavior
      return null unless @children.length > index >= @length

      @tmp = @children[@length]
      @children[@length] = @children[index]
      @children[index] = @tmp
      @tmp = null
      @length += 1
      return @children[@length - 1]

    if objectOrIndex == undefined && @length < @children.length
      @length += 1
      @children[@length - 1].reset() if typeof @children[@length - 1].reset == 'function'
      return @children[@length - 1]

    throw new Error('Pools need a factory function') if typeof @factory != 'function'

    @children.push @factory()
    @length += 1
    return @children[@length - 1]

  ###
  @description Deactivate an active object at a particular object/index
  ###
  deactivate: (objectOrIndex) ->
    index = if typeof objectOrIndex != 'number' then @children.indexOf(objectOrIndex) else objectOrIndex

    # TODO: Spec this behavior
    return null if index >= @length || index < 0

{'fraction_non_alphanumeric': 0.11375146084924036, 'fraction_numerical': 0.006622516556291391, 'mean_word_length': 3.178193653376729, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 23, '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': '2433873', 'n_tokens_mistral': 1487, 'n_tokens_neox': 1404, 'n_words': 508}