Skip to content

Commit 81be77e

Browse files
committed
Minor edits to replace old names, mostly. Tests pass.
1 parent 1b5b0d5 commit 81be77e

23 files changed

+126
-185
lines changed

doc/seq.dot

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,5 @@ digraph G {
2727

2828

2929

30-
Meta -> Obj;
30+
Meta -> MetaW;
3131
}

iseq/iseq.go

+3
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ type Equivable interface {
1717
// Hashable is the interface for types that support computing a hash code.
1818
// Two items that are Equiv should have the same hash code.
1919
type Hashable interface {
20+
21+
// Hashable extends Equivable
2022
Equivable
2123

2224
// Returns a hash code for the thing.
@@ -141,6 +143,7 @@ type Meta interface {
141143
}
142144

143145
// An MetaW is a Meta that also supports creating a copy with new metadata
146+
// This was originally clojure.lang.Obj
144147
type MetaW interface {
145148
Meta
146149
WithMeta(meta PMap) MetaW

murmur3/murmur3.go

+22-22
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ func HashUInt32(input uint32) uint32 {
3535
return 0
3636
}
3737

38-
key := mixKey(input)
39-
hash := mixHash(seed, key)
40-
return finalize(hash, 4)
38+
key := MixKey(input)
39+
hash := MixHash(seed, key)
40+
return Finalize(hash, 4)
4141
}
4242

4343
func HashUInt64(input uint64) uint32 {
@@ -48,13 +48,13 @@ func HashUInt64(input uint64) uint32 {
4848
low := uint32(input)
4949
high := uint32(input >> 32)
5050

51-
key := mixKey(low)
52-
hash := mixHash(seed, key)
51+
key := MixKey(low)
52+
hash := MixHash(seed, key)
5353

54-
key = mixKey(high)
55-
hash = mixHash(hash, key)
54+
key = MixKey(high)
55+
hash = MixHash(hash, key)
5656

57-
return finalize(hash, 8)
57+
return Finalize(hash, 8)
5858
}
5959

6060
func HashString(input string) uint32 {
@@ -65,8 +65,8 @@ func HashString(input string) uint32 {
6565
// step through the string 4 bytes at a time
6666
for i := 3; i < len; i += 4 {
6767
key := uint32(input[i-3]) | uint32(input[i-2]<<8) | uint32(input[i-1]<<16) | uint32(input[i]<<24)
68-
key = mixKey(key)
69-
hash = mixHash(hash, key)
68+
key = MixKey(key)
69+
hash = MixHash(hash, key)
7070
}
7171

7272
// deal with remaining characters
@@ -81,23 +81,21 @@ func HashString(input string) uint32 {
8181
case 3:
8282
key = uint32(input[len-3]) | uint32(input[len-2]<<8) | uint32(input[len-1]<<16)
8383
}
84-
key = mixKey(key)
85-
hash = mixHash(hash, key)
84+
key = MixKey(key)
85+
hash = MixHash(hash, key)
8686
}
8787

88-
return finalize(hash, int32(len))
88+
return Finalize(hash, int32(len))
8989
}
9090

91-
// implementation details
92-
93-
func mixKey(key uint32) uint32 {
91+
func MixKey(key uint32) uint32 {
9492
key *= c1
9593
key = rotateLeft(key, r1)
9694
key *= c2
9795
return key
9896
}
9997

100-
func mixHash(hash uint32, key uint32) uint32 {
98+
func MixHash(hash uint32, key uint32) uint32 {
10199
hash ^= key
102100
hash = rotateLeft(hash, r2)
103101
hash = hash*m + n
@@ -106,7 +104,7 @@ func mixHash(hash uint32, key uint32) uint32 {
106104
}
107105

108106
// finalize forces all bits of a hash block to avalanche
109-
func finalize(hash uint32, length int32) uint32 {
107+
func Finalize(hash uint32, length int32) uint32 {
110108
hash ^= uint32(length)
111109
hash ^= hash >> 16
112110
hash *= 0x85ebca6b
@@ -116,13 +114,15 @@ func finalize(hash uint32, length int32) uint32 {
116114
return hash
117115
}
118116

119-
func finalizeCollHash(hash uint32, count int32) uint32 {
117+
func FinalizeCollHash(hash uint32, count int32) uint32 {
120118
h1 := seed
121-
k1 := mixKey(hash)
122-
h1 = mixHash(h1, k1)
123-
return finalize(h1, count)
119+
k1 := MixKey(hash)
120+
h1 = MixHash(h1, k1)
121+
return Finalize(h1, count)
124122
}
125123

124+
// implementation details
125+
126126
func rotateLeft(x uint32, n uint32) uint32 {
127127
return (x << n) | (x >> (32 - n))
128128
}

seq/array_chunk.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,11 @@ func (a *arrayChunk) NthD(i int, notFound interface{}) interface{} {
4747
return notFound
4848
}
4949

50-
func (a *arrayChunk) NthE(i int, notFound interface{}) (interface{}, error) {
50+
func (a *arrayChunk) NthE(i int) (interface{}, error) {
5151
if i >= 0 && i < a.Count1() {
5252
return a.Nth(i), nil
5353
}
54-
return notFound, errors.New("Index out of bounds for chunk")
54+
return nil, errors.New("Index out of bounds for chunk")
5555
}
5656

5757
// interface Chunk

seq/chunked_seq.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ func newChunkedSeqRaw(v *PVector, node []interface{}, i int, offset int) *chunke
3838

3939
// interface MetaW
4040

41-
func (c *chunkedSeq) WithMeta(meta iseq.PMap) iseq.Obj {
41+
func (c *chunkedSeq) WithMeta(meta iseq.PMap) iseq.MetaW {
4242
if meta == c.meta {
4343
return c
4444
}
@@ -85,8 +85,7 @@ func (c *chunkedSeq) Empty() iseq.PCollection {
8585
}
8686

8787
func (c *chunkedSeq) Equiv(o interface{}) bool {
88-
// TODO: revisit Equiv
89-
return sequtil.Equals(c, o)
88+
return sequtil.Equiv(c, o)
9089
}
9190

9291
func (c *chunkedSeq) First() interface{} {

seq/cons.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ func NewConsM(meta iseq.PMap, first interface{}, more iseq.Seq) *Cons {
4343

4444
// interface iseq.MetaW
4545

46-
func (c *Cons) WithMeta(meta iseq.PMap) iseq.Obj {
46+
func (c *Cons) WithMeta(meta iseq.PMap) iseq.MetaW {
4747
return NewConsM(meta, c.first, c.more)
4848
}
4949

@@ -98,7 +98,7 @@ func (c *Cons) Equiv(o interface{}) bool {
9898
}
9999

100100
if os, ok := o.(iseq.Seqable); ok {
101-
return sequtil.SeqEquals(c, os.Seq())
101+
return sequtil.SeqEquiv(c, os.Seq())
102102
}
103103

104104
// TODO: handle built-in 'sequable' things such as arrays, slices, strings

seq/cons_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ func TestConsCtors(t *testing.T) {
3535
func TestConsImplementInterfaces(t *testing.T) {
3636
var c interface{} = NewCons("abc", nil)
3737

38-
if _, ok := c.(iseq.Obj); !ok {
39-
t.Error("Cons must implement Obj")
38+
if _, ok := c.(iseq.MetaW); !ok {
39+
t.Error("Cons must implement MetaW")
4040
}
4141

4242
if _, ok := c.(iseq.Meta); !ok {
@@ -51,7 +51,7 @@ func TestConsImplementInterfaces(t *testing.T) {
5151
t.Error("Cons must implement Seqable")
5252
}
5353

54-
if _, ok := c.(iseq.Equatable); !ok {
54+
if _, ok := c.(iseq.Equivable); !ok {
5555
t.Error("Cons must implement Equatable")
5656
}
5757

seq/emptylist.go

+3-6
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ package seq
66

77
import (
88
"github.com/dmiller/go-seq/iseq"
9-
"github.com/dmiller/go-seq/sequtil"
109
)
1110

1211
// EmptyList implements an empty iseq.PList
@@ -31,7 +30,7 @@ var (
3130

3231
// interface iseq.MetaW
3332

34-
func (e *EmptyList) WithMeta(meta iseq.PMap) iseq.Obj {
33+
func (e *EmptyList) WithMeta(meta iseq.PMap) iseq.MetaW {
3534
return &EmptyList{AMeta: AMeta{meta}}
3635
}
3736

@@ -48,7 +47,7 @@ func (e *EmptyList) Count() int {
4847
}
4948

5049
func (e *EmptyList) Cons(o interface{}) iseq.PCollection {
51-
return e.SCons(o)
50+
return e.ConsS(o)
5251
}
5352

5453
func (e *EmptyList) Empty() iseq.PCollection {
@@ -70,9 +69,7 @@ func (e *EmptyList) More() iseq.Seq {
7069
}
7170

7271
func (e *EmptyList) ConsS(o interface{}) iseq.Seq {
73-
// TODO: really, this needs to return a PList of one element.
74-
// Fix when we have a true PList
75-
return &Cons{first: o, more: e}
72+
return NewPList1(o)
7673
}
7774

7875
// interface Counted

seq/emptylist_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ import (
1212
func TestEmptyListImplementInterfaces(t *testing.T) {
1313
var c interface{} = CachedEmptyList
1414

15-
if _, ok := c.(iseq.Obj); !ok {
15+
if _, ok := c.(iseq.MetaW); !ok {
1616
t.Error("EmptyList must implement Obj")
1717
}
1818

1919
if _, ok := c.(iseq.Meta); !ok {
20-
t.Error("EmptyList must implement Meta")
20+
t.Error("EmptyList must implement MetaW")
2121
}
2222

2323
if _, ok := c.(iseq.PCollection); !ok {
@@ -40,7 +40,7 @@ func TestEmptyListImplementInterfaces(t *testing.T) {
4040
t.Error("EmptyList must implement Counted")
4141
}
4242

43-
if _, ok := c.(iseq.Equatable); !ok {
43+
if _, ok := c.(iseq.Equivable); !ok {
4444
t.Error("EmptyList must implement Equatable")
4545
}
4646

seq/map_entry.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ func (me MapEntry) Val() interface{} {
2424

2525
func (me MapEntry) Equiv(o interface{}) bool {
2626
if you, ok := o.(iseq.MapEntry); ok {
27-
return sequtil.Equals(me.key, you.Key()) && sequtil.Equals(me.val, you.Val())
27+
return sequtil.Equiv(me.key, you.Key()) && sequtil.Equiv(me.val, you.Val())
2828
}
2929
return false
3030
}

seq/phashmap.go

+6-7
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ func NewPHashMapFromItems(items ...interface{}) *PHashMap {
8383

8484
// interface iseq.MetaW
8585

86-
func (m *PHashMap) WithMeta(meta iseq.PMap) iseq.Obj {
86+
func (m *PHashMap) WithMeta(meta iseq.PMap) iseq.MetaW {
8787
return &PHashMap{AMeta: AMeta{meta},
8888
count: m.count,
8989
root: m.root,
@@ -430,7 +430,7 @@ func createArrayHmnodeSeq(meta iseq.PMap, nodes []hmnode, i int, s iseq.Seq) *ar
430430
return nil
431431
}
432432

433-
func (a *arrayHmnodeSeq) WithMeta(meta iseq.PMap) iseq.Obj {
433+
func (a *arrayHmnodeSeq) WithMeta(meta iseq.PMap) iseq.MetaW {
434434
return createArrayHmnodeSeq(meta, a.nodes, a.i, a.s)
435435
}
436436

@@ -446,7 +446,7 @@ func (a *arrayHmnodeSeq) Cons(o interface{}) iseq.PCollection {
446446
return NewCons(o, a)
447447
}
448448

449-
func (a *arrayHmnodeSeq) SCons(o interface{}) iseq.Seq {
449+
func (a *arrayHmnodeSeq) ConsS(o interface{}) iseq.Seq {
450450
return NewCons(o, a)
451451
}
452452

@@ -463,8 +463,7 @@ func (a *arrayHmnodeSeq) Empty() iseq.PCollection {
463463
}
464464

465465
func (a *arrayHmnodeSeq) Equiv(o interface{}) bool {
466-
// TODO: revisit Equiv
467-
return sequtil.Equals(a, o)
466+
return sequtil.Equiv(a, o)
468467
}
469468

470469
func (a *arrayHmnodeSeq) Seq() iseq.Seq {
@@ -742,8 +741,8 @@ func createHmnodeSeq3(array []interface{}, i int, s iseq.Seq) *hmnodeSeq {
742741
// hmnodeSeq must implement the following iseq interfaces:
743742
// Meta, MetaW, Seqable, PCollection, Seq
744743

745-
// interface iseq.Obj
746-
func (h *hmnodeSeq) WithMeta(meta iseq.PMap) iseq.Obj {
744+
// interface iseq.MetaW
745+
func (h *hmnodeSeq) WithMeta(meta iseq.PMap) iseq.MetaW {
747746
return &hmnodeSeq{AMeta: AMeta{meta}, array: h.array, i: h.i, s: h.s}
748747
}
749748

seq/phashmap_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ import (
1414
func TestPHashMapImplementInterfaces(t *testing.T) {
1515
var c interface{} = NewPHashMapFromItems("abc", "def")
1616

17-
if _, ok := c.(iseq.Obj); !ok {
18-
t.Error("PHashMap must implement Obj")
17+
if _, ok := c.(iseq.MetaW); !ok {
18+
t.Error("PHashMap must implement MetaW")
1919
}
2020

2121
if _, ok := c.(iseq.Meta); !ok {
@@ -46,7 +46,7 @@ func TestPHashMapImplementInterfaces(t *testing.T) {
4646
t.Error("PHashMap must implement Counted")
4747
}
4848

49-
if _, ok := c.(iseq.Equatable); !ok {
49+
if _, ok := c.(iseq.Equivable); !ok {
5050
t.Error("PHashMap must implement Equatable")
5151
}
5252

@@ -174,7 +174,7 @@ func TestPHashMapGoesBig(t *testing.T) {
174174
}
175175
}
176176

177-
// interface iseq.Obj
177+
// interface iseq.MetaW
178178

179179
// TODO: test WithMeta once we have PMap
180180

seq/plist.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ func NewPListFromSlice(init []interface{}) *PList {
5656

5757
// interface iseq.MetaW
5858

59-
func (p *PList) WithMeta(meta iseq.PMap) iseq.Obj {
59+
func (p *PList) WithMeta(meta iseq.PMap) iseq.MetaW {
6060
return NewPListMeta1N(meta, p.first, p.rest, p.count)
6161
}
6262

seq/plist_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ func TestNewPlist1N(t *testing.T) {
7777
func TestPListImplementInterfaces(t *testing.T) {
7878
var c interface{} = NewPList1("abc")
7979

80-
if _, ok := c.(iseq.Obj); !ok {
81-
t.Error("PList must implement Obj")
80+
if _, ok := c.(iseq.MetaW); !ok {
81+
t.Error("PList must implement MetaW")
8282
}
8383

8484
if _, ok := c.(iseq.Meta); !ok {
@@ -105,7 +105,7 @@ func TestPListImplementInterfaces(t *testing.T) {
105105
t.Error("PList must implement Counted")
106106
}
107107

108-
if _, ok := c.(iseq.Equatable); !ok {
108+
if _, ok := c.(iseq.Equivable); !ok {
109109
t.Error("PList must implement Equatable")
110110
}
111111

@@ -148,7 +148,7 @@ func TestPListSeq(t *testing.T) {
148148

149149
func TestPListCons(t *testing.T) {
150150
c1 := NewPList1("abc")
151-
c2 := c1.SCons("def")
151+
c2 := c1.ConsS("def")
152152

153153
if c2.First() != "def" {
154154
t.Error("Cons has a bad first element")

0 commit comments

Comments
 (0)