slog: remove unused files
Change-Id: I70bb284d7cc79e1c15d13d37da2c8dc8a3c41725
Reviewed-on: https://go-review.googlesource.com/c/exp/+/494395
Run-TryBot: Jonathan Amsterdam <jba@google.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
diff --git a/slog/list.go b/slog/list.go
deleted file mode 100644
index 7b505ea..0000000
--- a/slog/list.go
+++ /dev/null
@@ -1,85 +0,0 @@
-package slog
-
-// A list[T] is an immutable sequence.
-// It supports three operations: append, len and indexing (at).
-// The zero value is an empty list.
-//
-// Repeated calls to append happen in amortized O(1) space and time. (Appending
-// an element allocates one node directly, and the normalize operation always
-// doubles the front slice, so we can charge two slots to each element.)
-//
-// The len method takes constant time.
-//
-// The at method requires a normalized list, and then takes constant time.
-//
-// It is possible to obtain quadratic behavior by alternating append and at:
-// the normalize required by at is called for each appended element, causing
-// front to be copied each time.
-type list[T any] struct {
- front []T
- back *node[T] // reversed
- lenBack int
-}
-
-type node[T any] struct {
- el T
- next *node[T]
-}
-
-// append returns a new list consisting of the receiver with x appended.
-func (l list[T]) append(x T) list[T] {
- if l.front == nil {
- // Empty list; return one with one element.
- return list[T]{
- front: []T{x},
- back: nil,
- lenBack: 0,
- }
- }
- if l.lenBack == len(l.front) {
- // When there are as many elements in back as in front, grow
- // front and move all of back to it.
- l = l.normalize()
- }
- // Push a new node with the element onto back, which is stored in
- // reverse order.
- return list[T]{
- front: l.front,
- back: &node[T]{el: x, next: l.back},
- lenBack: l.lenBack + 1,
- }
-}
-
-// len returns the number of elements in the list.
-func (l list[T]) len() int {
- return len(l.front) + l.lenBack
-}
-
-// at returns the ith element of the list.
-// The list must be normalized.
-func (l list[T]) at(i int) T {
- if l.back != nil {
- panic("not normalized")
- }
- return l.front[i]
-}
-
-// normalize returns a list whose back is nil and whose front contains all the
-// receiver's elements.
-func (l list[T]) normalize() list[T] {
- if l.back == nil {
- return l
- }
- newFront := make([]T, len(l.front)+l.lenBack)
- copy(newFront, l.front)
- i := len(newFront) - 1
- for b := l.back; b != nil; b = b.next {
- newFront[i] = b.el
- i--
- }
- return list[T]{
- front: newFront,
- back: nil,
- lenBack: 0,
- }
-}
diff --git a/slog/list_test.go b/slog/list_test.go
deleted file mode 100644
index e0d2f73..0000000
--- a/slog/list_test.go
+++ /dev/null
@@ -1,39 +0,0 @@
-package slog
-
-import (
- "testing"
-
- "golang.org/x/exp/slices"
-)
-
-func TestList(t *testing.T) {
- var l list[int]
- for i := 0; i < 10; i++ {
- l = l.append(i)
- }
- l = l.normalize()
- var got, want []int
- for i := 0; i < l.len(); i++ {
- want = append(want, i)
- got = append(got, l.at(i))
- }
- if !slices.Equal(got, want) {
- t.Errorf("got %v, want %v", got, want)
- }
-}
-
-func TestListAlloc(t *testing.T) {
- for n := 1; n < 100; n++ {
- got := testing.AllocsPerRun(1, func() {
- var l list[int]
- for i := 0; i < n; i++ {
- l = l.append(i)
- }
- })
- want := 1.5 * float64(n)
- if got > want {
- t.Fatalf("n=%d: got %f allocations, want <= %f",
- n, got, want)
- }
- }
-}