<commit_before>package main

type RingBuffer struct {
    buffer []interface{}
    beginPos, endPos int
}

func (rb *RingBuffer) Slice() []interface{} {
    if rb.beginPos <= rb.endPos {
        return rb.buffer[rb.beginPos:rb.endPos+1]
    } else {
        return append(rb.buffer[rb.beginPos:], rb.buffer[:rb.endPos+1])
    }
}

func (rb *RingBuffer) Append(item interface{}) {
    if rb.beginPos == -1 || rb.endPos == -1 {
        rb.beginPos = 0
        rb.endPos = 0
        rb.buffer[0] = item
        return
    }

    if rb.endPos == len(rb.buffer) - 1 {
        rb.endPos = 0
    } else {
        rb.endPos++
    }

    if rb.beginPos == len(rb.buffer) - 1 {
        rb.beginPos = 0
    } else if rb.beginPos == rb.endPos {
        rb.beginPos++
    }

    rb.buffer[rb.endPos] = item
}

func NewRingBuffer(size int) *RingBuffer {
    return &RingBuffer{
        buffer: make([]interface{}, size),
        beginPos: -1,
        endPos: -1,
    }
}<commit_msg>added Item method for accessing an element of the RingBuffer; added InvalidIndexError for RingBuffer; Stringer interface now implemented by RingBuffer<commit_after>package main

import (
    "bytes"
    "fmt"
)

type RingBuffer struct {
    buffer []interface{}
    beginPos, endPos int
}

type InvalidIndexError struct {
    index int
}

func (iie *InvalidIndexError) Error() string {
    return fmt.Sprintf("%d is not a valid index for a ring buffer element", iie.index)
}

func (rb *RingBuffer) Item(index int) (interface{}, error) {
    if index < 0 || index >= len(rb.buffer) {
        return nil, &InvalidIndexError{index}
    }

    pos := rb.beginPos + index

    if pos >= len(rb.buffer) {
        pos -= len(rb.buffer)
    }

    return rb.buffer[pos], nil
}

func (rb *RingBuffer) Append(item interface{}) {
    if rb.beginPos == -1 || rb.endPos == -1 {
        rb.beginPos = 0
        rb.endPos = 0
        rb.buffer[0] = item
        return
    }

    if rb.endPos == len(rb.buffer) - 1 {
        rb.endPos = 0
    } else {
        rb.endPos++
    }

    if rb.beginPos == len(rb.buffer) - 1 {
        rb.beginPos = 0
    } else if rb.beginPos == rb.endPos {
        rb.beginPos++
    }

    rb.buffer[rb.endPos] = item
}

func (rb *RingBuffer) String() string {
    var buf bytes.Buffer
    buf.WriteString("[ ")

    for i := 0; i < len(rb.buffer) - 1; i++ {
        rbi, _ := rb.Item(i)
        buf.WriteString(fmt.Sprintf("%v ", rbi))
    }

    rbi, _ := rb.Item(len(rb.buffer) - 1)
    buf.WriteString(fmt.Sprintf("%v]", rbi))
    return buf.String()
}

func NewRingBuffer(size int) *RingBuffer {
    return &RingBuffer{
        buffer: make([]interface{}, size),
        beginPos: -1,
        endPos: -1,
    }
}
{'fraction_non_alphanumeric': 0.14222222222222222, 'fraction_numerical': 0.01037037037037037, 'mean_word_length': 2.2078384798099764, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 5, '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': '3046438', 'n_tokens_mistral': 958, 'n_tokens_neox': 920, 'n_words': 234}