See 'enterInCache' in 'kl.spad (second signature) and constant DIFF.

Aha. Thanks.

Since we are close to SortedCache... The following can do without the x parameter.

    linearSearch : (S, S -> Boolean) -> Union(S, "failed")
      ++ linearSearch(x, f) searches x in the cache, calling \spad{f(y)}
      ++ to determine whether x is equal to y.  It returns y from cache
      ++ if f(y) is true or "failed" if no such y exists.


    linearSearch(x : S, equal? : S -> Boolean) ==
        k : Integer := 0
        -- Can not use for loop because equal? can insert new elements
        -- and change cache_use
        while k < cache_use repeat
            vscan := cache
            y := vscan(k)
            equal?(y) => return y
            vscan := cache
            -- skip over elements possibly inserted by equal?
            while not(EQ(y, vscan(k))$Lisp) repeat k := k + 1
            k := k + 1
        return "failed"

Bur maybe it's not worth to change it.

Ralf

--
You received this message because you are subscribed to the Google Groups "FriCAS - 
computer algebra system" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to fricas-devel+unsubscr...@googlegroups.com.
To view this discussion visit 
https://groups.google.com/d/msgid/fricas-devel/9dc7d17d-b850-4e8d-b595-bec0bb558bd1%40hemmecke.org.

Reply via email to