Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIND /same option #1720

Open
rebolbot opened this issue Oct 26, 2010 · 4 comments
Open

FIND /same option #1720

rebolbot opened this issue Oct 26, 2010 · 4 comments

Comments

@rebolbot
Copy link
Collaborator

Submitted by: BrianH

The /same option would search for the SAME? value in a block-like series, rather than an equivalent value. For other types that FIND applies to, /same would be a noop because the equivalence tested is the same one used by SAME? already. This should be even faster than a normal FIND.

This request is partly in response to #1708.

; Example code:
find/same b :val

; Equivalent code:
forall b [if same? :val first b [break/return b]]

CC - Data [ Version: alpha 109 Type: Wish Platform: All Category: Native Reproduce: Always Fixed-in:none ]

@rebolbot
Copy link
Collaborator Author

Submitted by: maxim

YESSSS

I've had to make this using a looped find and same?

it is orders of magnitude faster on searches, when items from a dataset have to be searched in said dataset.  example, to get the new index after some sorting algorithm, or to get a row from a db search when your criteria is the result of a query in that database.
its also useful in GUIs to determine selection from a list which has several times the same text but from different sources.

@rebolbot
Copy link
Collaborator Author

Submitted by: maxim

this is much faster than above example
until [either (same? pick (r: find blk :val) 1 :val) [r][not blk: :r]]

@rebolbot
Copy link
Collaborator Author

Submitted by: BrianH

That would not be faster for blocks that contain a lot of references to equivalent but not the same object/module/block/whatever as the value you are looking for. The FIND does a full EQUAL?-style comparison, and enough of those add up quickly. SAME? is much faster than EQUAL?.

@rebolbot
Copy link
Collaborator Author

rebolbot commented Nov 2, 2010

Submitted by: maxim

I know SAME? is faster, but going through REBOL loops was soo much slower than FIND that except for that specific case you gave, it was several hundred times faster in most cases, the larger the series, the bigger the difference.

having FIND/SAME would make that several times faster on ALL datatypes, which is why I'd be really happy for this wish to be granted.  :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant