Slide 1

Slide 1 text

Laravel CollectionͷܭࢉྔΛௐ΂ͯΈͨ 1)1ษڧձ *OOPWBUPS+BQBO*OD ෋ॴ྄ &OHJOFFS

Slide 2

Slide 2 text

ܭࢉྔʹ͍͓ͭͯ͞Β͍ ຊ೔͸࣌ؒతܭࢉྔΛѻ͍·͢

Slide 3

Slide 3 text

ྫ͑͹ϨϏϡʔ͍ͯ͠Δ࣌

Slide 4

Slide 4 text

ʮ͜ͷॲཧ஗ͦ͏ʯ ͜Εͩͱ෼͔Γʹ͍͘ɻ ॲཧͷ࣌ؒత଎౓Λڞ௨஌ࣝͰ఻͍͑ͨ

Slide 5

Slide 5 text

ӳޠͩͱ Time Complexity ࣌ؒෳࡶੑ ϓϩάϥϜͷॲཧʹ ͲΕ͘Β͍͕͔͔࣌ؒΔ͔Λ ਺ֶతʹѻ͏

Slide 6

Slide 6 text

Oه๏ O(1) O(log n) O(n) O(n * log n) O(n^2) ϓϩάϥϜͷ࣌ؒతܭࢉྔΛද͢

Slide 7

Slide 7 text

Oه๏ σʔλྔ͕૿Ճͨ͠৔߹ͷ ॲཧ࣌ؒͷ૿Ճ܏޲͕෼͔Δ

Slide 8

Slide 8 text

[άϥϑҾ༻] ։ൃ৽ଔʹ๋͙ɺجຊͷΞϧΰϦζϜͱܭࢉྔ http://www.techscore.com/blog/2016/08/08/։ൃ৽ଔʹ๋͙ɺجຊͷΞϧΰϦζϜͱܭࢉྔ/ σʔλྔͱܭࢉྔ

Slide 9

Slide 9 text

ܭࢉྔͱΞϧΰϦζϜ ΞϧΰϦζϜ ܭࢉྔ όϒϧιʔτ 0 O? Ϛʔδιʔτ 0 OMPHO όΠφϦαʔν 0 MPHO ΞϧΰϦζϜʹΑͬͯܭࢉྔ͕ҟͳΔ

Slide 10

Slide 10 text

͞Βʹৄ͘͠஌Γ͍ͨਓ ਺ֶΨʔϧ4 ཚ୒ΞϧΰϦζϜ 2ষͱ6ষΛಡΉ΂͠

Slide 11

Slide 11 text

ຊ୊ʹ໭Δ

Slide 12

Slide 12 text

Laravel Collection֤ϝιουͷܭࢉྔ ΋͏ͪΐͬͱ͖Ε͍ʹ͠·͢…

Slide 13

Slide 13 text

ࡶʹ·ͱΊΔͱ • ΄ͱΜͲ O(n) • O(1) ͕9ݸ • O(n^2) Ҏ্͕8ݸ

Slide 14

Slide 14 text

ཁ஫ҙϝιου • collapse O(n^2) • crossJoin O(n^3) • diff O(n^t) • diffAssoc O(n^t) • flatMap O(n^2) • flatten O(n^2) • groupBy O(n^2) • intersect O(n^2)

Slide 15

Slide 15 text

࣮ଌͯ͠Έͨ

Slide 16

Slide 16 text

where - O(n) ॲཧ࣌ؒ(ඵ) σʔλ݅਺

Slide 17

Slide 17 text

count - O(1) ॲཧ࣌ؒ(ඵ) σʔλ݅਺

Slide 18

Slide 18 text

collapse - O(n^2) ॲཧ࣌ؒ(ඵ) σʔλ݅਺

Slide 19

Slide 19 text

crossJoin - O(n^3) ॲཧ࣌ؒ(ඵ) σʔλ݅਺

Slide 20

Slide 20 text

diff - O(n^t) ॲཧ࣌ؒ(ඵ) σʔλ݅਺ t͸field਺ʹґଘ͢Δ

Slide 21

Slide 21 text

ܭࢉྔ͕෼͔ͬͨͱͯ͠ Կ͔ྑ͍͜ͱ͋Δͷ͔ʁ

Slide 22

Slide 22 text

஌Βͳ͍ͱѱ͍͜ͱ͕ى͖Δ

Slide 23

Slide 23 text

࣮ࡍʹ͔͋ͬͨ΋͠Εͳ͍ ܭࢉྔ͕໰୊ʹͳͬͨίʔυྫ ※࣮࿩Λݩʹͨ͠ϑΟΫγϣϯͰ͢

Slide 24

Slide 24 text

શ݅औಘ ϖʔδϯάͷͨΊʹ શ݅ϧʔϓͰճ͢ ྫ1

Slide 25

Slide 25 text

શ݅औಘ ϖʔδϯάͷͨΊʹ શ݅ϧʔϓͰճ͢ ϖʔδͷޙ൒ʹߦ͚͹ߦ͘΄Ͳ ϧʔϓ͕ճͬͯ஗͘ͳΔ O(n) ྫ1

Slide 26

Slide 26 text

߹Θٕͤ O(n^2) O(n)ΛೖΕࢠʹ͢Ε͹ύϫʔΞοϓ ྫ2 ୈ1ϧʔϓͰશ݅ճ͢ O(n) ୈ2ϧʔϓ΋શ݅ճ͢ O(n)

Slide 27

Slide 27 text

ୈҰҾ਺͸࠷େͰ਺ඦ݅ఔ౓͕ͩͬͨ ୈೋҾ਺ͷσʔλ਺͕੒௕͍ͯͬͯ͠… ྫ2 ୈ1ϧʔϓͰશ݅ճ͢ O(n) ୈ2ϧʔϓ΋શ݅ճ͢ O(n)

Slide 28

Slide 28 text

ྫ2ͷΞϧΰϦζϜΛ࡞ͬͯ ࣮ଌͯ͠ΈΔ

Slide 29

Slide 29 text

σʔλྔʹΑΔੑೳͷྼԽ ॲཧ࣌ؒ(ඵ) σʔλ݅਺ (ୈ1,2 Ҿ਺ಉ͡)

Slide 30

Slide 30 text

ͪΌΜͱO(n^2)ͷ άϥϑʹͳͬͨ

Slide 31

Slide 31 text

ࣄલʹݕ஌Ͱ͖ͳ͍͔ʁ

Slide 32

Slide 32 text

࣮͸ྫ̍ɾ̎ͷίʔυ͸ ୯ମςετ -> ௨ա ड͚ೖΕςετ -> ௨ա ௨աͯ͠͠·͍ͬͯͨ…

Slide 33

Slide 33 text

ෛՙςετ ίʔυϨϏϡʔ ࣄલݕग़Մೳͳࡆ

Slide 34

Slide 34 text

ෛՙςετ σʔλྔ͕ലେʹͳΔ͜ͱ͕ Θ͔͍ͬͯΔϓϩμΫτ͸ߦ͍ͬͯΔɻ ௨ৗͷϓϩμΫτͩͱ ͋Μ·Γ΍ͬͯΔͷݟͨ͜ͱແ͍ɻ

Slide 35

Slide 35 text

ίʔυϨϏϡʔ ϨϏϡΞʔͷεΩϧ΍ܦݧʹґଘ ࣄલʹܭࢉྔʹ͍ͭͯ νʔϜ಺Ͱษڧձͱ͔ͯ͠Ε͹ ࢦఠˍमਖ਼͸؆୯ͩͱࢥ͏

Slide 36

Slide 36 text

؂ࢹπʔϧͰɺॲཧ࣌ؒͷϝτϦΫεΛݟͯ ཧ٧ΊͰॲཧ࣌ؒͷ஗͍෦෼ΛಛఆͰ͖Ε͹ ·͋ɺٴୈ఺ͩͱࢥ͏ɻ ࠷ѱݟಀͯ͠΋

Slide 37

Slide 37 text

͓·͚

Slide 38

Slide 38 text

ܭࢉྔ͕Ұ໨ྎવ

Slide 39

Slide 39 text

σʔλͷू·ΓΛѻ͏ϓϩάϥϜ͸ ܭࢉྔ͕໌ࣔ͞Ε͍ͯΔͱ͋Γ͕͍ͨ

Slide 40

Slide 40 text

͓͠·͍