Esempio n. 1
0
func (f Float) Greater(b interface{}) (bool, error) {
	fb, ok := b.(float64)
	if !ok {
		return false, stringError.StringError("parameters not float64")
	}
	return float64(f) > float64(fb), nil
}
Esempio n. 2
0
func (hf *HeapFactory) AdjustBack(s, ln int) error {
	if len(hf.Items) < ln {
		return stringError.StringError(fmt.Sprintf("$3:%d is longer then len of $1", ln))
	}

	np := (s - 1) / 2
	for ; np >= 0 && s > 0; np = (s - 1) / 2 {
		nchild := 2*np + 1
		if nchild < ln-1 {
			b, e := hf.Items[nchild+1].Compare(hf.Items[nchild])
			if e != nil {
				return e
			}
			if b {
				nchild++
			}
		}
		b, e := hf.Items[nchild].Compare(hf.Items[np])
		if e != nil {
			return e
		}
		if b {
			hf.Items[nchild], hf.Items[np] = hf.Items[np], hf.Items[nchild]
		} else {
			break
		}
	}
	return nil
}
Esempio n. 3
0
func (hf *HeapFactory) Adjust(s, ln int) error {
	if len(hf.Items) < ln {
		return stringError.StringError(fmt.Sprintf("$3:%d is longer then len of $1", ln))
	}
	nchild := 0
	for ; 2*s+1 < ln; s = nchild {
		nchild = 2*s + 1
		if nchild < ln-1 {
			b, e := hf.Items[nchild+1].Compare(hf.Items[nchild])
			if e != nil {
				return e
			}
			if b {
				nchild++
			}
		}
		b, e := hf.Items[nchild].Compare(hf.Items[s])
		if e != nil {
			return e
		}
		if b {
			hf.Items[nchild], hf.Items[s] = hf.Items[s], hf.Items[nchild]
		} else {
			break
		}
	}
	return nil
}
Esempio n. 4
0
func (t *Trie) Find(key ILengthAt) (ValueNInt, error) {
	b := t.array[0].base.NInt()
	if b < 0 {
		return ZeroFloatValue, stringError.StringError("trie not Init or Init error")
	}
	p := 0
	for i := 0; i < key.Length(); i++ {
		p = b + key.At(i) + 1

		if b == t.array[p].check {
			b = t.array[p].base.NInt()
		} else {
			return ZeroFloatValue, stringError.StringError("not found")
		}
	}
	p = b
	n := t.array[p].base
	if b == t.array[p].check {
		return n, nil
	}
	return ZeroFloatValue, stringError.StringError("not found")
}