mirror of
https://github.com/dolthub/dolt.git
synced 2026-01-25 10:26:22 -06:00
Change List to not use futures
This disables the compound list creation and its related tests
This commit is contained in:
@@ -88,6 +88,7 @@ func TestCompoundListGet(t *testing.T) {
|
||||
}
|
||||
|
||||
func SkipTestCompoundListReadWriteValue(t *testing.T) {
|
||||
// BUG 465
|
||||
assert := assert.New(t)
|
||||
cs := chunks.NewMemoryStore()
|
||||
cl := getFakeCompoundList("hi", "bye")
|
||||
@@ -109,7 +110,8 @@ func TestnewCompoundListFromValues(t *testing.T) {
|
||||
assert.Equal(uint64(2), vs.Len())
|
||||
}
|
||||
|
||||
func TestCompoundListAppend(t *testing.T) {
|
||||
func SkipTestCompoundListAppend(t *testing.T) {
|
||||
// BUG 465
|
||||
assert := assert.New(t)
|
||||
|
||||
var l List = getFakeCompoundList("hi", "bye")
|
||||
@@ -142,7 +144,8 @@ func TestCompoundListAppend(t *testing.T) {
|
||||
assert.True(rl1.Equals(rl3))
|
||||
}
|
||||
|
||||
func TestCompoundListSlice(t *testing.T) {
|
||||
func SkipTestCompoundListSlice(t *testing.T) {
|
||||
// BUG 465
|
||||
assert := assert.New(t)
|
||||
|
||||
l1 := getTestCompoundList(t)
|
||||
@@ -161,7 +164,8 @@ func TestCompoundListSlice(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func TestCompoundListSet(t *testing.T) {
|
||||
func SkipTestCompoundListSet(t *testing.T) {
|
||||
// BUG 465
|
||||
assert := assert.New(t)
|
||||
|
||||
l1 := getTestCompoundList(t)
|
||||
@@ -177,7 +181,8 @@ func TestCompoundListSet(t *testing.T) {
|
||||
assert.True(Bool(true).Equals(l4.Get(l1.Len() - 1)))
|
||||
}
|
||||
|
||||
func TestCompoundListInsert(t *testing.T) {
|
||||
func SkipTestCompoundListInsert(t *testing.T) {
|
||||
// BUG 465
|
||||
assert := assert.New(t)
|
||||
|
||||
l1 := getTestCompoundList(t)
|
||||
@@ -197,7 +202,8 @@ func TestCompoundListInsert(t *testing.T) {
|
||||
assert.True(l4.Equals(l5))
|
||||
}
|
||||
|
||||
func TestCompoundListRemove(t *testing.T) {
|
||||
func SkipTestCompoundListRemove(t *testing.T) {
|
||||
// BUG 465
|
||||
assert := assert.New(t)
|
||||
|
||||
l1 := getTestCompoundList(t)
|
||||
|
||||
@@ -57,3 +57,11 @@ func appendChunks(chunks []Future, f Future) []Future {
|
||||
|
||||
return chunks
|
||||
}
|
||||
|
||||
func appendValueToChunks(chunks []Future, v Value) []Future {
|
||||
if v.TypeRef().Kind() == RefKind {
|
||||
// TODO: Wrong ref here. We don't want the Ref of the Ref Value but the ref of the value it is referring to. BUG 464
|
||||
chunks = append(chunks, futureFromRef(v.Ref()))
|
||||
}
|
||||
return chunks
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ type List interface {
|
||||
}
|
||||
|
||||
func NewList(v ...Value) List {
|
||||
return newCompoundListFromValues(v, nil)
|
||||
return newListLeaf(v...)
|
||||
}
|
||||
|
||||
func valuesToFutures(list []Value) []Future {
|
||||
|
||||
@@ -38,7 +38,8 @@ func TestListLeafIteratorAt(t *testing.T) {
|
||||
assert.True(l.Slice(2, l.Len()).Equals(l2))
|
||||
}
|
||||
|
||||
func TestCompoundListIterator(t *testing.T) {
|
||||
func SkipTestCompoundListIterator(t *testing.T) {
|
||||
// BUG 465
|
||||
assert := assert.New(t)
|
||||
|
||||
l := getTestCompoundList(t)
|
||||
@@ -54,7 +55,8 @@ func TestCompoundListIterator(t *testing.T) {
|
||||
assert.True(l.Equals(l2))
|
||||
}
|
||||
|
||||
func TestCompoundListIteratorAt(t *testing.T) {
|
||||
func SkipTestCompoundListIteratorAt(t *testing.T) {
|
||||
// BUG 465
|
||||
assert := assert.New(t)
|
||||
|
||||
l := getTestCompoundList(t)
|
||||
|
||||
@@ -9,21 +9,31 @@ import (
|
||||
)
|
||||
|
||||
type listLeaf struct {
|
||||
list []Future
|
||||
ref *ref.Ref
|
||||
cs chunks.ChunkSource
|
||||
values []Value
|
||||
ref *ref.Ref
|
||||
}
|
||||
|
||||
func newListLeaf(v ...Value) List {
|
||||
return listLeafFromFutures(valuesToFutures(v), nil)
|
||||
// Copy because Noms values are supposed to be immutable and Go allows v to be reused (thus mutable).
|
||||
values := make([]Value, len(v))
|
||||
copy(values, v)
|
||||
return newListLeafNoCopy(values)
|
||||
}
|
||||
|
||||
func listLeafFromFutures(list []Future, cs chunks.ChunkSource) List {
|
||||
return listLeaf{list, &ref.Ref{}, cs}
|
||||
func newListLeafNoCopy(values []Value) List {
|
||||
return listLeaf{values, &ref.Ref{}}
|
||||
}
|
||||
|
||||
func listLeafFromFutures(fs []Future, cs chunks.ChunkSource) List {
|
||||
values := make([]Value, len(fs))
|
||||
for i, f := range fs {
|
||||
values[i] = f.Deref(cs)
|
||||
}
|
||||
return newListLeafNoCopy(values)
|
||||
}
|
||||
|
||||
func (l listLeaf) Len() uint64 {
|
||||
return uint64(len(l.list))
|
||||
return uint64(len(l.values))
|
||||
}
|
||||
|
||||
func (l listLeaf) Empty() bool {
|
||||
@@ -31,23 +41,20 @@ func (l listLeaf) Empty() bool {
|
||||
}
|
||||
|
||||
func (l listLeaf) Get(idx uint64) Value {
|
||||
return l.getFuture(idx).Deref(l.cs)
|
||||
return l.values[idx]
|
||||
}
|
||||
|
||||
func (l listLeaf) Iter(f listIterFunc) {
|
||||
for i, fut := range l.list {
|
||||
if f(fut.Deref(l.cs), uint64(i)) {
|
||||
fut.Release()
|
||||
for i, v := range l.values {
|
||||
if f(v, uint64(i)) {
|
||||
break
|
||||
}
|
||||
fut.Release()
|
||||
}
|
||||
}
|
||||
|
||||
func (l listLeaf) IterAll(f listIterAllFunc) {
|
||||
for i, fut := range l.list {
|
||||
f(fut.Deref(l.cs), uint64(i))
|
||||
fut.Release()
|
||||
for i, v := range l.values {
|
||||
f(v, uint64(i))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,11 +78,7 @@ func (l listLeaf) iterInternal(sem chan int, lf listIterAllFunc, offset uint64)
|
||||
sem <- 1
|
||||
go func(idx uint64) {
|
||||
defer wg.Done()
|
||||
|
||||
f := l.list[idx]
|
||||
v := f.Deref(l.cs)
|
||||
f.Release()
|
||||
|
||||
v := l.values[idx]
|
||||
lf(v, idx+offset)
|
||||
<-sem
|
||||
}(idx)
|
||||
@@ -110,14 +113,9 @@ func (l listLeaf) mapInternal(sem chan int, mf MapFunc, offset uint64) []interfa
|
||||
sem <- 1
|
||||
go func(idx uint64) {
|
||||
defer wg.Done()
|
||||
|
||||
f := l.list[idx]
|
||||
v := f.Deref(l.cs)
|
||||
f.Release()
|
||||
|
||||
v := l.values[idx]
|
||||
c := mf(v, idx+offset)
|
||||
<-sem
|
||||
|
||||
mu.Lock()
|
||||
values[idx] = c
|
||||
mu.Unlock()
|
||||
@@ -129,37 +127,38 @@ func (l listLeaf) mapInternal(sem chan int, mf MapFunc, offset uint64) []interfa
|
||||
}
|
||||
|
||||
func (l listLeaf) getFuture(idx uint64) Future {
|
||||
return l.list[idx]
|
||||
return futureFromValue(l.values[idx])
|
||||
}
|
||||
|
||||
func (l listLeaf) Slice(start uint64, end uint64) List {
|
||||
return listFromFutures(l.list[start:end], l.cs)
|
||||
return newListLeafNoCopy(l.values[start:end])
|
||||
}
|
||||
|
||||
func (l listLeaf) Set(idx uint64, v Value) List {
|
||||
b := make([]Future, len(l.list))
|
||||
copy(b, l.list)
|
||||
b[idx] = futureFromValue(v)
|
||||
return listFromFutures(b, l.cs)
|
||||
values := make([]Value, len(l.values))
|
||||
copy(values, l.values)
|
||||
values[idx] = v
|
||||
return newListLeafNoCopy(values)
|
||||
}
|
||||
|
||||
func (l listLeaf) Append(v ...Value) List {
|
||||
return listFromFutures(append(l.list, valuesToFutures(v)...), l.cs)
|
||||
values := append(l.values, v...)
|
||||
return newListLeafNoCopy(values)
|
||||
}
|
||||
|
||||
func (l listLeaf) Insert(idx uint64, v ...Value) List {
|
||||
b := make([]Future, len(l.list)+len(v))
|
||||
copy(b, l.list[:idx])
|
||||
copy(b[idx:], valuesToFutures(v))
|
||||
copy(b[idx+uint64(len(v)):], l.list[idx:])
|
||||
return listFromFutures(b, l.cs)
|
||||
values := make([]Value, len(l.values)+len(v))
|
||||
copy(values, l.values[:idx])
|
||||
copy(values[idx:], v)
|
||||
copy(values[idx+uint64(len(v)):], l.values[idx:])
|
||||
return newListLeafNoCopy(values)
|
||||
}
|
||||
|
||||
func (l listLeaf) Remove(start uint64, end uint64) List {
|
||||
b := make([]Future, uint64(len(l.list))-(end-start))
|
||||
copy(b, l.list[:start])
|
||||
copy(b[start:], l.list[end:])
|
||||
return listFromFutures(b, l.cs)
|
||||
values := make([]Value, uint64(len(l.values))-(end-start))
|
||||
copy(values, l.values[:start])
|
||||
copy(values[start:], l.values[end:])
|
||||
return newListLeafNoCopy(values)
|
||||
}
|
||||
|
||||
func (l listLeaf) RemoveAt(idx uint64) List {
|
||||
@@ -172,9 +171,7 @@ func (l listLeaf) Ref() ref.Ref {
|
||||
|
||||
// BUG 141
|
||||
func (l listLeaf) Release() {
|
||||
for _, f := range l.list {
|
||||
f.Release()
|
||||
}
|
||||
// TODO: Remove?
|
||||
}
|
||||
|
||||
func (l listLeaf) Equals(other Value) bool {
|
||||
@@ -185,8 +182,8 @@ func (l listLeaf) Equals(other Value) bool {
|
||||
}
|
||||
|
||||
func (l listLeaf) Chunks() (futures []Future) {
|
||||
for _, f := range l.list {
|
||||
futures = appendChunks(futures, f)
|
||||
for _, v := range l.values {
|
||||
futures = appendValueToChunks(futures, v)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
@@ -165,20 +165,6 @@ func TestListRemoveAt(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func TestListFutures(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
cs := chunks.NewTestStore()
|
||||
v := NewString("hello")
|
||||
r := WriteValue(v, cs)
|
||||
f := futureFromRef(r)
|
||||
|
||||
l := listFromFutures([]Future{f, futureFromValue(Int64(0xbeefcafe))}, cs)
|
||||
|
||||
assert.Len(l.Chunks(), 1)
|
||||
assert.EqualValues(r, l.Chunks()[0].Ref())
|
||||
}
|
||||
|
||||
func TestListMap(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
|
||||
@@ -133,7 +133,7 @@ func TestSetFutures(t *testing.T) {
|
||||
r := WriteValue(v, cs)
|
||||
f := futureFromRef(r)
|
||||
|
||||
s := listFromFutures([]Future{f, futureFromValue(Int64(0xbeefcafe))}, cs)
|
||||
s := setFromFutures([]Future{f, futureFromValue(Int64(0xbeefcafe))}, cs)
|
||||
|
||||
assert.Len(s.Chunks(), 1)
|
||||
assert.EqualValues(r, s.Chunks()[0].Ref())
|
||||
|
||||
@@ -42,7 +42,8 @@ func doTreeWalk2(f Future, cs chunks.ChunkSource, cb SomeCallback, skip bool) {
|
||||
doTreeWalk2(f, cs, cb, true)
|
||||
}
|
||||
case listLeaf:
|
||||
for _, f := range v.list {
|
||||
for _, v := range v.values {
|
||||
f := futureFromValue(v)
|
||||
doTreeWalk(f, cs, cb)
|
||||
}
|
||||
case Map:
|
||||
|
||||
@@ -27,12 +27,14 @@ func TestWalkAll(t *testing.T) {
|
||||
m := write(NewMap(b, i, f, s))
|
||||
se := write(NewSet(b, i, f, s, bl))
|
||||
l2 := write(NewList(l))
|
||||
l3 := write(getTestCompoundList(t))
|
||||
// BUG 465
|
||||
// l3 := write(getTestCompoundList(t))
|
||||
|
||||
l3Expected := NewSet(l3)
|
||||
for i := 0; i < 0xff; i++ {
|
||||
l3Expected = l3Expected.Insert(UInt8(i))
|
||||
}
|
||||
// BUG 465
|
||||
// l3Expected := NewSet(l3)
|
||||
// for i := 0; i < 0xff; i++ {
|
||||
// l3Expected = l3Expected.Insert(UInt8(i))
|
||||
// }
|
||||
|
||||
tests := []struct {
|
||||
v Value
|
||||
@@ -47,7 +49,8 @@ func TestWalkAll(t *testing.T) {
|
||||
{m, NewSet(m, b, i, f, s)},
|
||||
{se, NewSet(se, b, i, f, s, bl)},
|
||||
{l2, NewSet(l2, l, b, i, f, s, bl)},
|
||||
{l3, l3Expected},
|
||||
// BUG 465
|
||||
// {l3, l3Expected},
|
||||
}
|
||||
|
||||
for _, t := range tests {
|
||||
|
||||
Reference in New Issue
Block a user