« Return to Thread: quoestion on index/1

quoestion on index/1

by Lukas Degener-2 :: Rate this Message:

Reply to Author | View in Thread

Hi,
I was reading through the online help entry for index/1.
There are two things that I am not sure I understand:

"Indexing as specified by this predicate uses a quick but linear scan."
Does this mean that the process of creating an index uses a linear scan,
or that index lookups are linear?

Then further down, there is this subclass example.
It is recommended there that if one wants to use the predicate
sub_type/2 for both finding subtypes and supertypes, one should resort
to index/1. But on the other hand, it is said that lookups will still be
linear - which sounds dramatically worse than those of the hash index
structure that is used by default.

What is this index/1 thing good for, if the lookup is still linear? The
manual states that "this type of indexing makes selecting clauses much
faster". Could you give more details on what this indexing actually does?


And finally, at least for dynamic predicates with a lot of clauses,
wouldn't it make more sense to use two predicates (one for each
"direction")?
Something like this:

:- dynamic sub_type_X/2, sub_type_XX/2.

sub_type(Sub,Super):-
    (    nonvar(Super)
    ->  sub_type_X(Sub,Super)
    ;   sub_type_XX(Super,Sub)
    ).

TIA + Regards,
--lu

------------
For further info, please visit http://www.swi-prolog.org/

To unsubscribe, send a plaintext mail with "unsubscribe prolog <e-mail>"
in its body to majordomo@...

 « Return to Thread: quoestion on index/1

LightInTheBox - Buy quality products at wholesale price