Skip to content

Latest commit

 

History

History
140 lines (95 loc) · 2.48 KB

hash.adoc

File metadata and controls

140 lines (95 loc) · 2.48 KB

Datový typ hash!

1. Úvodem

Hodnota typu hash! poskytuje rozhraní ve formě bloku s rychlým vyhledáváním.

Výchozí hešovací funkce je uživatelskou implementací algoritmu MurmurHash3

Typ hash! je člen těchto typesetů: default!, series!, any-block! a any-list!

2. Vytvoření

Hodnoty typu hash! lze vytvořit pouze za běhu programu s použitím konstruktoru make nebo konverzí to:

>> list: make hash! [a 123 "hello" b c 789]
nebo
>> list: to hash! [a 123 "hello" b c 789]

== make hash! [a 123 "hello" b c 789]

3. Přístup k elementům objektu hash!

3.1. Použitím notace path!

Získání hodnoty s použitím c jako klíče:

>> list/c
== 789

Nastavení hodnoty s použitím c jako klíče:

>> list/c: 42
== 42

>> list
== make hash! [a 123 "hello" b c 42]

3.2. Použitím slova find

>> find list 'b
== make hash! [b c 42]

3.3. Použitím slova select

>> dict: make hash! [a 123 b 456 c 789]
== make hash! [a 123 b 456 c 789]

>> select dict 'c
== 789

>> select dict 456
== c

>> dict: make hash! [2 123 4 456 6 2 8 789]
== make hash! [2 123 4 456 6 2 8 789]

>> select/skip dict 2 2
== 123

4. Operace se sadami dat

S hešovými hodnotami jsou možné následující 'množinové' operace: difference, exclude, intersect, union, unique.

>> dict1: make hash! [a 123 b 456 c 789]
== make hash! [a 123 b 456 c 789]

>> dict2: make hash! [2 123 4 456 6 2 8 789]
== make hash! [2 123 4 456 6 2 8 789]
>> difference dict1 dict2
== make hash! [a b c 2 4 6 8]
>> exclude dict1 dict2
== make hash! [a b c]
>> intersect dict1 dict2
== make hash! [123 456 789]
>> union dict1 dict2
== make hash! [a 123 b 456 c 789 2 4 6 8]
>> unique dict2
== make hash! [2 123 4 456 6 8 789]

5. Komparace

Na hodnotu hash! lze aplikovat všechny komparační operátory: =, ==, <>, >, <, >=, <=, =?. Navíc je také podporována funkce min a max.

6. Testování hodnot

Idiomem hash? ověříme, zda je hodnota typu hash!.

>> hash? dict1
== true

Typ dané hodnoty zjistíme dotazem type?:

>> type? dict2
== hash!

7. Předdefinovaná slova

7.1. Funkce

average, hash?, path-thru, sum, to-hash

7.2. Nativa

checksum, difference, exclude, extend, intersect, union, unique