in reply to Re^4: Testing if an array contains a value and then deleting it in most efficient way
in thread Testing if an array contains a value and then deleting it in most efficient way
Update: No, I guess I'm wrong. The nested loops (while and firstidx confused me).
while ( -1 < ( $i = firstidx { $_ == $val } @array ) ) { ... }
is best case O(N).
is worse case O(N2).
for (0 .. $#array) { next if $_ != $var; ... }
is best, real & worse case O(N).
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^6: Testing if an array contains a value and then deleting it in most efficient way
by ikegami (Patriarch) on Feb 19, 2008 at 03:59 UTC | |
by parv (Parson) on Feb 19, 2008 at 08:49 UTC |