ããŒã¿æ§é ãšã¯
ããŒã¿æ§é , ãŸãã¯ðåã·ã¹ãã ã«ãããããŒã¿å.
ããŒã¿ã®éãŸããã³ã³ãã¥ãŒã¿ã®äžã§å¹æçã«æ±ããã, äžå®ã®åœ¢åŒã«ç³»çµ±ç«ãŠãŠæ ŒçŽãããšãã®åœ¢åŒ.
Index
倧ãããããŠ, åºæ¬å, ð代æ°ããŒã¿åãšðæœè±¡ããŒã¿å(ADT)ããã.
- ðããªããã£ãå: èšèªã§ãµããŒããããå
- æœè±¡ããŒã¿å (ADT): èªèº«ã§å®çŸ©ããå.
- 代æ°ããŒã¿å:
- åæå: åæå - Wikipedia
- çŽåå:
- çŽç©å: 代æ°çããŒã¿å - Wikipedia
- æœè±¡ããŒã¿å: æœè±¡ããŒã¿å - Wikipedia
- æ§é äœ:
- ã¯ã©ã¹:
- ã€ã³ã¿ãã§ãŒã¹:
- 代æ°ããŒã¿å:
Java ã€ã³ã¿ãã§ãŒã¹ã¯, éå±€ãæããªãåã·ã¹ãã ãæ§ç¯ãã.
ð代æ°ããŒã¿å
代æ°ããŒã¿å(Algebraic data type), é¢æ°åãã©ãã€ã ã§å©çšããã.
ããããã®ä»£æ°çããŒã¿åã®å€ã«ã¯,以äžããã£ãŠãã.
- 1 å以äžã®ã³ã³ã¹ãã©ã¯ã¿
- åã³ã³ã¹ãã©ã¯ã¿ã«ã¯ 0 å以äžã®åŒæ°
2 åŒæ°ã§äžããããä»ã®ããŒã¿åã®å€ã, ã³ã³ã¹ãã©ã¯ã¿ã§å ãã ãããªãã®.
Enum: åæå
ããã°ã©ããéžãã åã ã®èå¥åããã®ãŸãŸæééåãšããŠæã€æœè±¡ããŒã¿å.
çªå·ãæããªãã«ããŽãªå€æ°. äžæã®æå.
å®è¡æã«ã¯, çªå·ãæ¯ãããããšãèŠãã, èšèªã«ãã£ãŠã¯çªå·ã¯ããã°ã©ãã«èŠããªãããšããã.
Struct: çŽç©å
å éšã«å€ãæã€å. ä»èšèªã®æ§é äœã«çžåœ.
Union: çŽåå
åæåã«ãã£ãŒã«ããä»å ããããšã§, è€æ°ã®çŽç©åãå®çŸ©ãããã®ã§ã. åæåãšçŽç©åã®äž¡æ¹ã®ç¹åŸŽã䜵ãæã£ãŠããŸã.
C èšèªã§ã¯å ±çšäœã«çžåœããŸãã, C èšèªã®ããã«å ±çšäœã®ãã£ãŒã«ããéžã¶ããšã§è§£éãå€ããããšã¯ã§ããŸãã.
ref. Haskell 代æ°çããŒã¿å è¶ å ¥é - Qiita
æœè±¡ããŒã¿åãšã®æ¯èŒ
Wikipedia ãã.
é¢æ°åèšèªã§æœè±¡ããŒã¿åãå®çŸããææ³ã®ã²ãšã€ã«, ã¢ãžã¥ãŒã«ã·ã¹ãã ã«ããã¹ã³ãŒãå¶éãå©çšããŠ, ã³ã³ã¹ãã©ã¯ã¿ãæ©èœã, åã®ã¿ãå ¬éãã, ãšããææ³ããã.
ããŒã¿ã³ã³ã¹ãã©ã¯ã¿ãã®ãã®ã®ä»£ããã«, çžåœããåŒæ°ããšã£ãŠ, ç®çã®åã®å€ãè¿ããããª, ã³ã³ã¹ãã©ã¯ã¿ãæœè±¡åããé¢æ°ãå®çŸ©ã, ãã¡ãã®é¢æ°ãå ¬éãã. ãã®é¢æ°ã, ãªããžã§ã¯ãæåèšèªã«ãããã³ã³ã¹ãã©ã¯ã¿ã«çžåœãã.
CPMCP ãã.
ã«ãã»ã«åãšå€æ§äœããããããš, ADT ã«ãªã.
ãªããžã§ã¯ãåã§ã¯, å éšç¶æ ãæã€ã®ã«å¯ŸããŠ, Haskell ã®ãããªä»£æ°çããŒã¿åã§ã¯, å€ã®éåãå®çŸ©ããã®ã¿ã§, æäœãå®çŸ©ããå Žå, å¥ã«é¢æ°å®çŸ©ãã.
ðæœè±¡ããŒã¿å(ADT)
æœè±¡ããŒã¿å(Abstract data type, ADT)ãšã¯, ããŒã¿æ§é ãšãã®æäœãå®çŸ©ããããŒã¿å.
æ§é åããã°ã©ãã³ã°ã¯ä»®æ³æ©æ¢°ã¢ãã«ã«åºã¥ã段éç詳现åæ³ (stepwise refinement) ããããããã, ããŒã¿æ§é ã®å€æŽãè¡ããšå€æŽéšåããœãŒã¹ã³ãŒãäžã«æ£åšããŠããŸããšãã匱ç¹ããã£ã. ããŒã¿æœè±¡ã®æŠå¿µã¯ãã®æ¬ ç¹ãè£å®ãããã®ã§ãã£ã.
An ADT consists of a set of values and a set of operations.
- Integer å
- Value:1,2,3
- Operation:+
- Stack å
- Value: elemtent
- Operation: push, pop, âŠ
Value ãš Operation ããèªäœã¯ State ãæããªã. CTMCP, p433
ãã³ãã«ãããŠããªãããŒã¿æœè±¡.
cf. å ±éã®ã¡ãœãããæäŸããåã®éåã ã¯ã©ã¹(Class) ãšãã.
ðã©ãããŒ(Wrapper Pattern)
ADT ã« ã¢ã¯ã»ã¹ããããã® key (ããŒ) ãå°å ¥ããããšã§å®å šã«ã¢ã¯ã»ã¹ããããšãã§ãã.
å€ã®éåã«çŽæ¥ã¢ã¯ã»ã¹ãããªãããã®æäœ.(CPMCP p210)
- å€ãå®å šã«ä¿æããããã«ã¯ éµ (key) ãå©çšã㊠(å ã) æäœãè¿œå ããã°ãã.
Key={NewName}
SS={Chunk.new w (Key:S)}
å ã¿, ã»ã©ããè¡ãããŒã¿æœè±¡ã ã©ãã㌠ãšå®çŸ©ãã.
proc {NewWrapper ?Wrap ?Unwrap}
Key={NewName} in
fun {Wrap X}
{Chunk.new w{Key:X}}
end
fun {Unwrap X}
try W.Key catch _ then raise error (unwrap (W)) end end
end
end
以äžã®ããã«, Wrap, Unwrap ãã.
S={a b c}
SS={Wrap S}
S={Unwrap SS}
ãã®ãã¿ãŒã³ã«ã¯ðãã¯ãã掻çšã§ãããã.
ç¶æ ããã€ADT
Diference between ADT and Object. Stack ãã€ãã£ãå®è£ ã®éã.
ðæ§é äœ(Stateful ADT)
local Wrap Unwrap in
{NewWrapper Wrap Unwrap}
fun {NewStack} {Wrap nil} end
fun {Push W X} {Wrap X|{Unwrap W}} end
fun {Pop W X} S={Unwrap W} in X=S.1 {Wrap S.2} end
fun {IsEmpty W} {Unwrap W}==nil end
end
ãã®ææ³ã¯ Stateful ADT ãšãã.
ãããŠ, C èšèªã§ã¯ãããã£ãŠããŒã¿æœè±¡åãè¡ãããšãããã. ãã¡ããé¢æ°ãã€ã³ã¿é åã䜿ãã° C èšèªã§ã Object ãã€ããããšãã§ãããå®éã«ã¯ãããŸã§ãããªã(é¢å).
Object
ãªããžã§ã¯ãã§ã¯ããŒã¿ã«å¯Ÿããæäœã¯ããã·ãŒãžã£å€æ°ãšããŠæ±ãããããšã«æ³šç®.
fun {NewStack}
C={NewCell nil}
proc {Push X} C:=X|@C end
proc {Pop X} S=@C in X=S.1 C:=S.2 end
fun {IsEmpty} @C==nil end
in
stack (push:Push pop:Pop isEmpty:IsEmpty)
end
ãªããžã§ã¯ãæåèšèªã¯,åã« Object ããµããŒãããèšèªã§ã¯ãªããŠ, Abstruct Data Type ã匷åã«ãµããŒãããŠãã. Object ãš ADT ã®æå³ããã£ã¡ãã«ã€ããããŠããã®ãçŸå®ã®çŸç¶.
References
- refs:
ðã³ã¬ã¯ã·ã§ã³/Collection
ã³ã¬ã¯ã·ã§ã³, ãŸãã¯ã³ã³ãããšã¯ãªããžã§ã¯ãã®éãŸããè¡šçŸããããŒã¿æ§é .
ã³ã³ãã (ããŒã¿å) - Wikipedia
Index
- é
å
- ã¹ã¿ãã¯
- ãã¥ãŒ
- é£æ³é
åããŒã¿ãšå¥ã®ããŒã¿ãããŒã¿æ§é ãäžå¯Ÿäžã«é¢é£ä»ããŠæ ŒçŽãã
- ããã·ã¥ããŒãã«
- ã«ãã¯ã¢ããããŒãã«
- ç·åœ¢ãªã¹ã: ããŒã¿ã次㮠(ãããã¯åã®) ããŒã¿ãžã®åç
§ãæã€.
- ðã°ã©ã/Graph: ããŒã¿ãä»»æã®ä»ã®ããŒã¿ãžã®åç §ãæã€.
- ðããªãŒ(Tree): æšæ§é , äžã€ã®é ç¹ããæš¹ç¶ã«æåããããã°ã©ã.
ðRecord
ããŒã¿ãšå¥ã®ããŒã¿ãããŒã¿æ§é ãäžå¯Ÿäžã«é¢é£ä»ããŠæ ŒçŽãããã®.
ãã£ãšãåºæ¬çãªããŒã¿å.
- Atom
- Tuple
- List
ðã¿ãã«(Tuple/Struct)
ç°ãªãããŒã¿åã§ãã£ãŠãæ ŒçŽã§ãã. ãã¯ãã«ããªã¹ãã¯åããã¹ãŠåããã®ããæ ŒçŽã§ããªã.
Record, Struct, æ§é äœãšå矩ã§å©çšãããããšããã.
ðãªã¹ã/List
ç·åœ¢ãªã¹ãæ§é . ããŒã¿ã次㮠(ãããã¯åã®) ããŒã¿ãžã®åç §ãæã€.
- ðã¹ããªãŒã /Streams: ãªã¹ãã®çµç«¯ãUnbound Value.
ðããªãŒæ§é /Tree
æšæ§é . ðã°ã©ã/Graphã®æŽŸçæ§é .
ðããŒãæ§é
ããªãŒæ§é ã®äžã§, 芪èŠçŽ ãåèŠçŽ ããåžžã«å€§ããïŒãããã¯å°ããïŒãšããæ¡ä»¶ãæºãããã®.
ðãã¥ãŒ/Queue
ãã¥ãŒ(queue)ãšã¯, åŸ ã¡è¡åãè¡šçŸããããŒã¿æ§é .
ðFIFO
First in First Out(FIFO). å¥å, First Come First Served(FCFS).
ãã¥ãŒã«ãããããŒã¿ã®åãåºãé åºã®èŠåŸ.
ãã¥ãŒã®æäœ
èšèªãã©ã€ãã©ãªã«ãã£ãŠååãéããã®ã®, 倧äœä»¥äžã®æ©èœããã.
- push/enque: ãã¥ãŒã«ããŒã¿ãå ¥ãã, ãšã³ãã¥ãŒ.
- pop: dequeue: ãã¥ãŒããããŒã¿ãåãåºã, ããã¥ãŒ.
- peek: ãã¥ãŒããããŒã¿ãåãåºã(äžèº«ã¯åé€ããªã).
peek(queue)
ãã¥ãŒããããŒã¿ãåãåºã(äžèº«ã¯åé€ããªã). ããšãã°ãã¥ãŒã®å é ãèŠãããšããªã©.
Related
- ð¡Clojureã§FIFOãã¥ãŒãæ±ã
- ãã¥ãŒ (ã³ã³ãã¥ãŒã¿) - Wikipedia
- Queueing theory - Wikipedia
ðã¹ã¿ãã¯/Stack
åŸå ¥ãå åºãæ¹åŒ(LIFO)ã®ãªã¹ãããŒã¿æ§é . ã¹ã¿ãã¯.
ðãã¥ãŒ(queue)ã®å察.
LIFO
ã¹ã¿ãã¯ã«ãããã¢ã«ãŽãªãºã .
ðã»ãã/Set
ã»ãã(set), æ¥æ¬èªã§ã¯éåãšãåŒã°ãã. ã³ã³ãã¥ãŒã¿ããã°ã©ãã³ã°ã®çšèª.
é åºã®ãªãããŒã¿ã®éãŸããè¡šçŸããæœè±¡ããŒã¿å, åäžã®ããŒã¿ã¯äžã€ããå«ãŸããªãããšãä¿èšŒããã.
ðé£æ³é å(Associative Array)
é£æ³é åã®é¡çŸ©èª
- é£æ³ãªã¹ã/é£æ³ã³ã³ãã
- ããã
- ããã·ã¥
- ãã£ã¯ã·ã§ããª(èŸæžé å)
Related
Links
ðããŒã¿ãã¬ãŒã
ããŒã¿åŠçãããããã®è¡åããŒã¿æ§é . ããŒãã«, 衚圢åŒãšããã.
èšèªå¥
- Python: ðpandas
- R: ð§data.table
- Clojure: ð§tech.ml.dataset
Basics
ðå(Column)
ãã¯ãã«æŒç®ã§åŠçããã.