示例#1
0
文件: helpers.go 项目: dmiller/go-seq
func moreFromSeq(s iseq.Seq) iseq.Seq {
	sn := s.Next()
	if sn == nil {
		return CachedEmptyList
	}
	return sn
}
示例#2
0
文件: pvector.go 项目: dmiller/go-seq
// Create a PVector from an ISeq
func NewPVectorFromISeq(items iseq.Seq) *PVector {
	// TODO: redo when we have transients
	var ret iseq.PVector = EmptyPVector
	for ; items != nil; items = items.Next() {
		ret = ret.ConsV(items.First())
	}
	return ret.(*PVector)
}
示例#3
0
文件: count.go 项目: dmiller/go-seq
// SeqCount computes the length of an iseq.Seq
// Only call this on known non-empty iseq.Seq
func SeqCount(s0 iseq.Seq) int {
	i := 1 // if we are here, it is non-empty
	for s := s0.Next(); s != nil; s, i = s.Next(), i+1 {
		if cnt, ok := s.(iseq.Counted); ok {
			return i + cnt.Count1()
		}
	}
	return i
}
示例#4
0
文件: hash.go 项目: dmiller/go-seq
// HashUnordered computes a hash for an iseq.Seq, independent of order of elements
func HashUnordered(s iseq.Seq) uint32 {
	n := int32(0)
	hash := uint32(0)

	for ; s != nil; s = s.Next() {
		hash += Hash(s.First)
		n++
	}
	return murmur3.FinalizeCollHash(hash, n)
}
示例#5
0
func NewPTreeMapFromSeqC(items iseq.Seq, comp iseq.CompareFn) *PTreeMap {

	ret := CreateEmptyPTreeMap(comp)

	for i := 0; items != nil; items, i = items.Next().Next(), i+1 {
		if items.Next() == nil {
			panic(fmt.Sprintf("No value supplied for key: %v", items.First()))
		}
		ret = ret.AssocM(items.First(), items.Next().First()).(*PTreeMap)
	}
	return ret
}
示例#6
0
func NewPHashMapFromSeq(items iseq.Seq) *PHashMap {
	// TODO: transients
	ret := EmptyPHashMap

	for i := 0; items != nil; items, i = items.Next().Next(), i+1 {
		if items.Next() == nil {
			panic(fmt.Sprintf("No value supplied for key: %v", items.First()))
		}
		ret = ret.AssocM(items.First(), items.Next().First()).(*PHashMap)
		// if checkDup && ret.Count1() != i+1 {
		// 	panic(fmt.Sprintf("Duplicate key: %v",items.First()))
		// }
	}
	return ret
}