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
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
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
300
バックアップしていますか?
tsudaahr
0
170
RDB以前のファイル設計の話でもしようか(ぇ
tsudaahr
0
180
NPUわからん
tsudaahr
0
230
計算量オーダーの話
tsudaahr
1
490
クラウド初学者が抱える不安について
tsudaahr
0
470
等幅は死んだ(ぇ
tsudaahr
0
160
いくら眺めてもエラーの理由がわからないコードについて
tsudaahr
0
250
Other Decks in Programming
See All in Programming
iOS 27でニュースアプリはどう変わる!? 〜日経電子版の新機能対応と、開発事例から〜
lynnswap
7
13k
Verilogで学ぶCPU自作入門
uyuki234
8
4.1k
ソニーのクラウド共通基盤の変遷とAI時代の開発スタイルに合わせた進化 / The Journey of Sony’s Common Cloud Platform and Its Evolution for AI-Native Development
kenjiyoneyama
0
270
月間100万人のサービス刷新で、 技術選定をHonoに振り切った話
yutobara
8
6.6k
Agentic Software Factoryに、すごく賢いIF文を。 / super smart IF statement into the Agentic Software Factory.
rkaga
8
2.2k
TechTown - Creating Composable Callables in Contemporary C++
rollbear
0
130
JIS keyboard support in Omarchy
lef237
0
110
C#の現在地 進化の歴史と、AI時代の.NET Everywhere
neuecc
5
5.2k
Web Framework Benchmark Battle 2026, Any%
a_matsuda
2
2k
IBM Bob Dojo #1 仕様駆動開発入門
oniak3ibm
PRO
0
390
re:Inventに行く前に知っておきたい現地参加のノウハウ
nokomoro3
0
430
Event is what happens
moro
2
770
Featured
See All Featured
How GitHub (no longer) Works
holman
316
150k
How To Stay Up To Date on Web Technology
chriscoyier
790
250k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
12
1.3k
The B2B funnel & how to create a winning content strategy
katarinadahlin
PRO
1
570
Hiding What from Whom? A Critical Review of the History of Programming languages for Music
tomoyanonymous
3
1.3k
Google's AI Overviews - The New Search
badams
0
1.6k
Stewardship and Sustainability of Urban and Community Forests
pwiseman
0
550
Test your architecture with Archunit
thirion
2
2.4k
The Invisible Side of Design
smashingmag
301
52k
The Straight Up "How To Draw Better" Workshop
denniskardys
239
140k
The Director’s Chair: Orchestrating AI for Truly Effective Learning
tmiket
1
330
Building Better People: How to give real-time feedback that sticks.
wjessup
370
20k
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?