Ejemplo n.º 1
0
func moreFromSeq(s iseq.Seq) iseq.Seq {
	sn := s.Next()
	if sn == nil {
		return CachedEmptyList
	}
	return sn
}
Ejemplo n.º 2
0
// 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)
}
Ejemplo n.º 3
0
// 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
}
Ejemplo n.º 4
0
// 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)
}
Ejemplo 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
}
Ejemplo n.º 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
}