@@ -23,15 +23,25 @@ type List interface {
2323 // At returns the item at the given position in the map. It will
2424 // panic if the index is out of range.
2525 At (int ) Value
26- AtInto (Allocator , int ) Value
26+ // AtUsing uses the provided allocator and returns the item at the given
27+ // position in the map. It will panic if the index is out of range.
28+ // The returned Value should be given back to the Allocator when no longer needed
29+ // by calling Allocator.Free(Value).
30+ AtUsing (Allocator , int ) Value
2731 // Range returns a ListRange for iterating over the items in the list.
2832 Range () ListRange
29- RangeInto (Allocator ) ListRange
30-
31- // Equals compares the two list, and return true if they are the same, false otherwise.
33+ // RangeUsing uses the provided allocator and returns a ListRange for
34+ // iterating over the items in the list.
35+ // The returned Range should be given back to the Allocator when no longer needed
36+ // by calling Allocator.Free(Value).
37+ RangeUsing (Allocator ) ListRange
38+ // Equals compares the two lists, and return true if they are the same, false otherwise.
3239 // Implementations can use ListEquals as a general implementation for this methods.
3340 Equals (List ) bool
34- EqualsInto (Allocator , List ) bool
41+ // EqualsUsing uses the provided allocator and compares the two lists, and return true if
42+ // they are the same, false otherwise. Implementations can use ListEqualsUsing as a general
43+ // implementation for this methods.
44+ EqualsUsing (Allocator , List ) bool
3545}
3646
3747// ListRange represents a single iteration across the items of a list.
@@ -60,23 +70,25 @@ func (_ *emptyRange) Item() (index int, value Value) {
6070// ListEquals compares two lists lexically.
6171// WARN: This is a naive implementation, calling lhs.Equals(rhs) is typically the most efficient.
6272func ListEquals (lhs , rhs List ) bool {
63- return ListEqualsInto ( defaultAllocator , lhs , rhs )
73+ return ListEqualsUsing ( HeapAllocator , lhs , rhs )
6474}
6575
66- func ListEqualsInto (a Allocator , lhs , rhs List ) bool {
76+ // ListEqualsUsing uses the provided allocator and compares two lists lexically.
77+ // WARN: This is a naive implementation, calling lhs.EqualsUsing(allocator, rhs) is typically the most efficient.
78+ func ListEqualsUsing (a Allocator , lhs , rhs List ) bool {
6779 if lhs .Length () != rhs .Length () {
6880 return false
6981 }
7082
71- lhsRange := lhs .RangeInto (a )
83+ lhsRange := lhs .RangeUsing (a )
7284 defer a .Free (lhsRange )
73- rhsRange := rhs .RangeInto (a )
85+ rhsRange := rhs .RangeUsing (a )
7486 defer a .Free (rhsRange )
7587
7688 for lhsRange .Next () && rhsRange .Next () {
7789 _ , lv := lhsRange .Item ()
7890 _ , rv := rhsRange .Item ()
79- if ! EqualsInto (a , lv , rv ) {
91+ if ! EqualsUsing (a , lv , rv ) {
8092 return false
8193 }
8294 }
@@ -91,12 +103,15 @@ func ListLess(lhs, rhs List) bool {
91103// ListCompare compares two lists lexically. The result will be 0 if l==rhs, -1
92104// if l < rhs, and +1 if l > rhs.
93105func ListCompare (lhs , rhs List ) int {
94- return ListCompareInto ( defaultAllocator , lhs , rhs )
106+ return ListCompareUsing ( HeapAllocator , lhs , rhs )
95107}
96- func ListCompareInto (a Allocator , lhs , rhs List ) int {
97- lhsRange := lhs .RangeInto (a )
108+
109+ // ListCompareUsing uses the provided allocator and compares two lists lexically. The result will be 0 if l==rhs, -1
110+ // if l < rhs, and +1 if l > rhs.
111+ func ListCompareUsing (a Allocator , lhs , rhs List ) int {
112+ lhsRange := lhs .RangeUsing (a )
98113 defer a .Free (lhsRange )
99- rhsRange := rhs .RangeInto (a )
114+ rhsRange := rhs .RangeUsing (a )
100115 defer a .Free (rhsRange )
101116
102117 for {
@@ -116,7 +131,7 @@ func ListCompareInto(a Allocator, lhs, rhs List) int {
116131 }
117132 _ , lv := lhsRange .Item ()
118133 _ , rv := rhsRange .Item ()
119- if c := CompareInto (a , lv , rv ); c != 0 {
134+ if c := CompareUsing (a , lv , rv ); c != 0 {
120135 return c
121136 }
122137 // The items are equal; continue.
0 commit comments