Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
キューとは何か
Search
tsuda.a
April 24, 2024
Programming
310
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
キューとは何か
キューが分からない、何に使うか不明、という話があったので、リングバッファを用いた例を使って説明を試みました。
tsuda.a
April 24, 2024
More Decks by tsuda.a
See All by tsuda.a
Git を GUI で使う話
tsudaahr
0
140
マジカルインクリメントと指数表記
tsudaahr
0
290
バックアップしていますか?
tsudaahr
0
170
RDB以前のファイル設計の話でもしようか(ぇ
tsudaahr
0
180
NPUわからん
tsudaahr
0
230
計算量オーダーの話
tsudaahr
1
490
クラウド初学者が抱える不安について
tsudaahr
0
470
等幅は死んだ(ぇ
tsudaahr
0
150
いくら眺めてもエラーの理由がわからないコードについて
tsudaahr
0
250
Other Decks in Programming
See All in Programming
動作中のプログラムの中身をリアルタイムに覗く / Realtime Debugger for CSharp with Roslyn
prota
1
1.7k
Unity6 URPによる海底をテーマにしたVJシステムの解説 | Unity Shader 完全に理解した 勉強会
gam0022
0
300
Augmenting AI with the Power of Jakarta EE
ivargrimstad
0
390
Verilogで学ぶCPU自作入門.pdf
uyuki234
7
3.9k
カツオ、ご期待ください
suneo3476
0
140
AWS CDKのカスタムリソースでContinuum(旧Security Agent)を実装した話 | Implementing Continuum (formerly Security Agent) via AWS CDK Custom Resource
akihisaikeda
2
120
WebRTC映像をAirPlayに対応させる挑戦.pdf
monolithic_adam
0
330
Findy - エンジニア向け会社紹介/Findy Company Deck
findyinc
6
400k
Vue Fes Japan 2026 タイムテーブル徹底解説
448jp
1
590
Workers Cache を知る
syumai
0
320
AWSに止められる覚悟してますか?
morizo_1984
2
500
モジュールの視点からSwiftを読み解く #iosdc
s_shimotori
0
300
Featured
See All Featured
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
33
5k
Thoughts on Productivity
jonyablonski
76
5.4k
Claude Code どこまでも/ Claude Code Everywhere
nwiizo
68
58k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
367
27k
Odyssey Design
rkendrick25
PRO
2
850
Noah Learner - AI + Me: how we built a GSC Bulk Export data pipeline
techseoconnect
PRO
0
440
Max Prin - Stacking Signals: How International SEO Comes Together (And Falls Apart)
techseoconnect
PRO
0
470
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
9
1.6k
GraphQLの誤解/rethinking-graphql
sonatard
75
12k
A better future with KSS
kneath
240
18k
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.8k
AI Search: Implications for SEO and How to Move Forward - #ShenzhenSEOConference
aleyda
1
1.4k
Transcript
キューとは何か? すごい広島570 with IT初心者の会 85 LTDD 2024-3 #3 @tsuda_ahr
お題 • キューが分からない、何に使うか不明、という話があったので説明を試みて みます。
話すこと • 原始的な、データ構造としてのキューの話をします。
元ネタ https://speakerdeck.com/satoshi256kbyte/konpiyutasaiensuniokerukiyutosutatukunojie-shuo
この説明に疑問を持った
どこが疑問だったか • 並列並行処理とキューの説明が混在している。 • 待ち時間や輻輳の話も含まれている。 • 負荷の平準化(負荷分散)についても述べられている。 • 多分Amazon SQS
(Simple Queue Service) とかのサービスを念頭 に置いている。 • つまり、キューの説明としては盛り込みすぎでは?
ということで • 原始的なキューの目的やデータ構造についての説明を試みます。
そもそも「キュー」とは何か • 処理しないとならない、山積みの書類のこと(ぇ #比喩表現です念のため
現実だとこんな感じ キューから取り出して作業 する人 (下から取る) 山積みの書類 (キュー本体) キューに入れる人 (上にのせる)
応用1) 複数で処理する
応用2) Web(しろめ Web Server
手近な例 • レジ待ち。
コンピューターでは? • データ構造の一種として扱われる。
実装例 • たとえばリングバッファを使用する場合
リングバッファとは? • 末尾まで使うと先頭に戻ってくるような使い方をするバッファ 2 3 4 5 6 7 0
1 0 1 2 3 4 5 6 7 実際のリングバッファ リングバッファの概念図
ということで。 • キューの動きを追ってみます。
キューの動き(1) 5 1 6 2 0 7 4 3 5
6 2 0 7 4 3 5 1 6 0 7 4 3 1 2 Read ポインター : 0 Writeポインター : 0 Read ポインター : 0 Writeポインター : 1 Read ポインター : 0 Writeポインター : 2 初期状態 Enqueue(1) Enqueue(2) 書き込み 書き込み
キューの動き(2) 5 6 2 0 7 4 3 5 6
2 0 7 3 5 1 6 0 7 3 1 4 2 Read ポインター : 0 Writeポインター : 3 Read ポインター : 1 Writeポインター : 3 Read ポインター : 1 Writeポインター : 4 1 4 Enqueue(3) Dequeue(1) Enqueue(4) 書き込み 書き込み 読み込み
キューの動き(3) 5 6 0 7 4 3 5 1 6
2 0 7 5 1 6 0 7 3 1 4 2 Read ポインター : 2 Writeポインター : 4 Read ポインター : 3 Writeポインター : 4 Read ポインター : 4 Writeポインター : 4 2 3 4 Dequeue(2) Dequeue(3) Dequeue(4) 読み込み 読み込み 読み込み
特徴 • 固定長のバッファ(=固定サイズのメモリ)で実装可能。 • Read ポインターと Write ポインターに差があると、未読み出しのデータが ある。 •
バッファ数-1 のデータを蓄積可能。 (先の例の場合、バッファ数は 8 なので、7 データまで蓄積可能)
欠点 • バッファサイズに上限がある。 • なので最近はリスト構造などを使った無限長のキューの実装が多いのではな いか?
何がうれしいのか? • レジ待ちとほぼ一緒 • 要求の順番で処理ができる。 • 処理するほうは、一つずつ順番に処理できる。 • 要求するほうは、要求だけして逃げることもできる(=待たずに他の処理ができる)
デメリット • 要求に対して処理結果が即座に返せるなら、キューを使うメリットはほぼない。 • 順番は保証されるが、いつ結果が戻ってくるかはわからない。 • キューが長すぎるとひたすら戻ってこない。 • 今回説明した実装では、優先度を上げたりキャンセルしたりはできない。
こちらからは以上です。 • Any Question?