Re: Optimizing multiple searches
- Posted by _tom (admin) Jun 29, 2017
- 1286 views
search.e library takes some untangling before use.
Always look to the idea that Euphoria divides options into two: atom|sequence, one|many, 0|1 .
- You are searching for something in a sequence or a string sequence.
- An item is "usualy often an atom, but could be an object viewed as one whole."
- An {items list} is "several items that could satisfy the search."
- A slice is "a contiguous sequence that is part of an equal or longer sequence."
- A {slices list} is "several slices that could satisfy the search."
- A "new" sequence is "returned after a search and replace action."
find
A find function "locates an item in a list."
input | search result | use | |
---|---|---|---|
item | 0|1 | is_in_list | is_in_range |
index | find | rfind | |
{ indices } | find_all | find_all_but | |
"new" | find_replace | ||
|
|
|
|
{ items list } | 0|1 | match_any | |
index | find_any | ||
{ indices } | find_each |
Warning: the match_any function does not fit the naming pattern.
match
A match function "locates a slice in a list."
input | search result | use | |
---|---|---|---|
slice | 0|1 | begins | ends |
index | match | ||
{ indices } | match_all | ||
"new" | match_replace |
Note: for {slices list} you have to write nested loops.
Wanted Search Libray
An improved std/search.e would not have any conflicts with the std/regex.e library.
A lowercase search function ( find, match ) uses one item as a search argument. An uppercase search function ( Find, Match ) uses a list of items as a search argument.
find
A find function "searches for an item in a list."
A Find function "searches for {items} in a list."
input | search result | use | |
---|---|---|---|
item | 0|1 | is_in_list | is_in_range |
index | find | rfind | |
{ indices } | find_all | find_all_but | |
"new" | find_replace | ||
|
|
|
|
{ items list } | 0|1 | ||
index | Find | ||
{ indices } | Find_all |
A match function "searches for a slice in a list." A Match function "searches for {slices} in a list."
input | search result | use | |
---|---|---|---|
slice | 0|1 | begins | ends |
index | match | ||
{ indices } | match_all | ||
"new" | match_replace | ||
|
|
|
|
{ items list } | 0|1 | ||
index | Match | ||
{ indices } | Match_all |
_tom