1

For this first row found idiom (w∘{(↓⍺)⍳↓⍵}) there seems no reduction in search time even though the first search would be hashing the array making later searches much faster?

      w← 100000000 3⍴'123'
      w←w,[1]'321'

      z← ⎕AI[3] ⋄ w∘{(↓⍺)⍳↓⍵}'321' ⋄ (⎕AI[3])-z
100000001
2892
      z← ⎕AI[3] ⋄ w∘{(↓⍺)⍳↓⍵}'321' ⋄ (⎕AI[3])-z
100000001
2883

1 Answer 1

0

From the documentation:

Notice that retaining the hash table pays off only on a second or subsequent application of the derived function. This usually occurs in one of two ways: either the derived function is named for later (and repeated) use, as in the first example below or it is applied repeatedly as the operand of a primitive or defined operator, as in the second example.

      w←100000000 3⍴'123'
      w←w,[1]'321'

      f←w∘{(↓⍺)⍳↓⍵}
      z←⎕AI[3] ⋄ f'321' ⋄ (⎕AI[3])-z
100000001
2782
      z←⎕AI[3] ⋄ f'321' ⋄ (⎕AI[3])-z
100000001
16

Try it online!

      w←100000000 3⍴'123' 
      w←w,[1]'321' 

      w∘{(↓⍺)⍳↓⍵}{z←⎕AI[3] ⋄ ⎕←⍺⍺ ⍵ ⋄ ⎕←(⎕AI[3])-z}¨'321' '321'
100000001
2375
100000001
0

Try it online!

5
  • Nice payoff on very large arrays. Any other idioms for general purpose lookups that retain the hashed table or some other data structure? Jun 14, 2018 at 20:25
  • @JoeKillian They are all listed in the documentation I linked.
    – Adám
    Jun 14, 2018 at 20:27
  • The Try It Link is to Tio showing the same idiom for testing and I know of the main Idiom page here help.dyalog.com/16.0/Content/Language/… but I think there is a way to hash a table then apply perhaps commonly used functions on it. This is what I meant. Hash a table and what other commonly used phrases are there that might time benefit. There are probably quite a few but say just the top three. Or is this the only idiom or commonly used phrase that makes great use of a hash table? Jun 14, 2018 at 21:28
  • Oops, I know see the link you were talking about. Jun 14, 2018 at 21:29
  • @JoeKillian It may also have your interest to hash an array independently of creating an ad hoc function.
    – Adám
    Jun 14, 2018 at 21:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.