diff --git a/ring-buffer/mpoquet.tmTheme b/ring-buffer/mpoquet.tmTheme new file mode 100644 index 0000000000000000000000000000000000000000..9b3a803c3c6d56d167bb4e89c0a2239cc8fbf06a --- /dev/null +++ b/ring-buffer/mpoquet.tmTheme @@ -0,0 +1,374 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> +<plist version="1.0"> +<dict> + <key>author</key> + <string>Ankur Gupta</string> + <key>name</key> + <string>GitHub Clean White</string> + <key>settings</key> + <array> + <dict> + <key>settings</key> + <dict> + <key>background</key> + <string>#FFFFFF</string> + <key>caret</key> + <string>#000000</string> + <key>foreground</key> + <string>#000000</string> + <key>invisibles</key> + <string>#B3B3B3F4</string> + <key>lineHighlight</key> + <string>#0000001A</string> + <key>selection</key> + <string>#BAD6FD</string> + </dict> + </dict> + <dict> + <key>name</key> + <string>String</string> + <key>scope</key> + <string>string</string> + <key>settings</key> + <dict> + <key>foreground</key> + <string>#C41A16</string> + </dict> + </dict> + <dict> + <key>name</key> + <string>Number</string> + <key>scope</key> + <string>constant.numeric</string> + <key>settings</key> + <dict> + <key>foreground</key> + <string>#0086B3</string> + </dict> + </dict> + <dict> + <key>name</key> + <string>Keyword</string> + <key>scope</key> + <string>keyword</string> + <key>settings</key> + <dict> + <key>foreground</key> + <string>#A71D5D</string> + </dict> + </dict> + <dict> + <key>name</key> + <string>Operator</string> + <key>scope</key> + <string>keyword.operator</string> + <key>settings</key> + <dict> + <key>foreground</key> + <string>#000000</string> + </dict> + </dict> + <dict> + <key>name</key> + <string>Built-in constant</string> + <key>scope</key> + <string>constant.language</string> + <key>settings</key> + <dict> + <key>foreground</key> + <string>#0086B3</string> + </dict> + </dict> + <dict> + <key>name</key> + <string>Exception</string> + <key>scope</key> + <string>support.class.exception</string> + <key>settings</key> + <dict> + <key>foreground</key> + <string>#990000</string> + </dict> + </dict> + <dict> + <key>name</key> + <string>Function name</string> + <key>scope</key> + <string>entity.name.function</string> + <key>settings</key> + <dict> + <key>foreground</key> + <string>#000000</string> + <!-- <key>fontStyle</key> + <string>italic</string> --> + </dict> + </dict> + <dict> + <key>name</key> + <string>Type name</string> + <key>scope</key> + <string>entity.name.type</string> + <key>settings</key> + <dict> + <key>fontStyle</key> + <string>bold underline</string> + </dict> + </dict> + <dict> + <key>name</key> + <string>Arguments</string> + <key>scope</key> + <string>variable.parameter</string> + <key>settings</key> + <dict> + <key>fontStyle</key> + <string>italic</string> + </dict> + </dict> + <dict> + <key>name</key> + <string>Comment</string> + <key>scope</key> + <string>comment</string> + <key>settings</key> + <dict> + <!-- <key>fontStyle</key> + <string>italic</string> --> + <key>foreground</key> + <string>#707070</string> + </dict> + </dict> + <dict> + <key>name</key> + <string>Invalid</string> + <key>scope</key> + <string>invalid</string> + <key>settings</key> + <dict> + <!-- <key>background</key> + <string>#E71A114D</string> --> + <key>foreground</key> + <string>#FF0000</string> + </dict> + </dict> + <dict> + <key>name</key> + <string>Trailing whitespace</string> + <key>scope</key> + <string>invalid.deprecated.trailing-whitespace</string> + <key>settings</key> + <dict> + <key>background</key> + <string>#E71A1100</string> + </dict> + </dict> + <dict> + <key>name</key> + <string>Embedded source</string> + <key>scope</key> + <string>text source</string> + <key>settings</key> + <dict> + <key>background</key> + <string>#FAFAFAFC</string> + <key>foreground</key> + <string>#000000</string> + </dict> + </dict> + <dict> + <key>name</key> + <string>Tag</string> + <key>scope</key> + <string>meta.tag, declaration.tag</string> + <key>settings</key> + <dict> + <key>foreground</key> + <string>#AA0D91</string> + </dict> + </dict> + <!-- <dict> + <key>name</key> + <string>Constant</string> + <key>scope</key> + <string>constant, support.constant</string> + <key>settings</key> + <dict> + <key>foreground</key> + <string>#000000</string> + </dict> + </dict> --> + <dict> + <key>name</key> + <string>Support</string> + <key>scope</key> + <string>support</string> + <key>settings</key> + <dict> + <key>fontStyle</key> + <string>bold</string> + <key>foreground</key> + <string>#000000</string> + </dict> + </dict> + <dict> + <key>name</key> + <string>Storage</string> + <key>scope</key> + <string>storage</string> + <key>settings</key> + <dict> + <!-- <key>fontStyle</key> + <string>bold</string> --> + <key>foreground</key> + <string>#AA0D91</string> + </dict> + </dict> + <dict> + <key>name</key> + <string>Section name</string> + <key>scope</key> + <string>entity.name.section</string> + <key>settings</key> + <dict> + <key>fontStyle</key> + <string>bold underline</string> + </dict> + </dict> + <dict> + <key>name</key> + <string>Frame title</string> + <key>scope</key> + <string>entity.name.function.frame</string> + <key>settings</key> + <dict> + <key>fontStyle</key> + <string>bold</string> + <key>foreground</key> + <string>#000000</string> + <!-- <string>#881280</string> --> + </dict> + </dict> + <dict> + <key>name</key> + <string>XML Declaration</string> + <key>scope</key> + <string>meta.tag.preprocessor.xml</string> + <key>settings</key> + <dict> + <key>foreground</key> + <string>#333333</string> + </dict> + </dict> + <dict> + <key>name</key> + <string>html attribute</string> + <key>scope</key> + <string>entity.other.attribute-name</string> + <key>settings</key> + <dict> + <key>fontStyle</key> + <string>italic</string> + <key>foreground</key> + <!-- <string>#3366CC</string> --> + <string>#0A8585</string> + </dict> + </dict> + <dict> + <key>name</key> + <string>html tag punctuation</string> + <key>scope</key> + <string>entity.name.tag</string> + <key>settings</key> + <dict> + <key>foreground</key> + <string>#121289</string> + <!-- <key>fontStyle</key> + <string>bold</string> --> + </dict> + </dict> + <!-- Adding stuff for diff. This works in ST3 --> + <dict> + <key>name</key> + <string>diff header from</string> + <key>scope</key> + <string>meta.diff.header.from-file</string> + <key>settings</key> + <dict> + <key>background</key> + <string>#FFDDDD</string> + <key>fontStyle</key> + <string></string> + <key>foreground</key> + <string>#000000</string> + </dict> + </dict> + <dict> + <key>name</key> + <string>diff header to</string> + <key>scope</key> + <string>meta.diff.header.to-file</string> + <key>settings</key> + <dict> + <key>background</key> + <string>#DDFFDD</string> + <key>fontStyle</key> + <string></string> + <key>foreground</key> + <string>#000000</string> + </dict> + </dict> + <dict> + <key>name</key> + <string>diff inserted</string> + <key>scope</key> + <string>markup.inserted.diff</string> + <key>settings</key> + <dict> + <key>background</key> + <string>#DDFFDD</string> + <key>fontStyle</key> + <string></string> + </dict> + </dict> + <dict> + <key>name</key> + <string>diff deleted</string> + <key>scope</key> + <string>markup.deleted.diff</string> + <key>settings</key> + <dict> + <key>background</key> + <string>#FFDDDD</string> + <key>fontStyle</key> + <string></string> + <key>foreground</key> + <string>#000000</string> + </dict> + </dict> + <!-- BracketHighlighter colors --> + <dict> + <key>name</key> + <string>BH Color</string> + <key>scope</key> + <string>brackethighlighter.default</string> + <key>settings</key> + <dict> + <key>foreground</key> + <string>#FF992244</string> + <key>fontStyle</key> + <string>italic</string> + </dict> + </dict> + </array> + <key>uuid</key> + <string>26786979-843B-4FE2-BCB6-4FCEC6F8FB58</string> + <key>colorSpaceName</key> + <string>sRGB</string> + <key>semanticClass</key> + <string>theme.light.git_hub_clean_white</string> + <key>comment</key> + <string>v1.0 Feb 1, 2015 +Made to look as close to GitHub as possible.</string> +</dict> +</plist> diff --git a/ring-buffer/ring-buffer.pdf b/ring-buffer/ring-buffer.pdf new file mode 100644 index 0000000000000000000000000000000000000000..3b676ce0c5117a667f03e7d440372c89c6bb703a Binary files /dev/null and b/ring-buffer/ring-buffer.pdf differ diff --git a/ring-buffer/ring-buffer.typ b/ring-buffer/ring-buffer.typ new file mode 100644 index 0000000000000000000000000000000000000000..de0de0ab6f3a8e9c1622c71a1e8640bc9bbc3dcf --- /dev/null +++ b/ring-buffer/ring-buffer.typ @@ -0,0 +1,109 @@ +#import "@preview/touying:0.6.1": * +#import themes.metropolis: * +#import "@preview/cetz:0.3.4" +#import "@preview/codly:1.3.0": * +#import "@preview/codly-languages:0.1.8": * + +#set raw(theme: "mpoquet.tmTheme") +#show: codly-init.with() +#codly(display-name: false) + +#show strong: it => text(fill: luma(10%), it) + +#let cetz-canvas = touying-reducer.with(reduce: cetz.canvas, cover: cetz.draw.hide.with(bounds: true)) + +#show: metropolis-theme.with( + aspect-ratio: "16-9", + footer: self => self.info.institution, + config-info( + title: [Ring buffer], + subtitle: [_and in the darkness bind them_], + author: [Millian #smallcaps[Poquet]], + date: [2025-04-29], + ), +) +#title-slide() + +== Qu'est-ce à dire que ceci ? +Différents noms pour la même chose : `(ring|cyclic|circular) (buffer|queue|array)` + +Accès +- `put` : ajout d'un élément +- `get` : récupération d'un élément + +Éléments clés +- Sémantique de file : les éléments ajoutés en premier sont récupérés en premier +- Buffer à *taille fixe* de `N` cases +- Utilisation de deux indices : têtes de lecture `r` et d'écriture `w` + +Utilité +- Séquençage d'information entre deux composants matériels +- File de messages (synchronisée) entre deux composants logiciels + +== Exemple d'exécution +#let ringbuf(buf, w, r) = cetz-canvas({ + import cetz.draw: * + grid((0,0), (buf.len(),1), step: 1) + translate(x: .5, y: .5) + for i in range(buf.len()) { + content((i, 0), [#buf.at(i)]) + } + translate(y: -0.75) + if (w != r) { + content((r,0), [`r`]) + content((w,0), [`w`]) + } else { + content((r,0), [`rw`]) + } +}) + +#grid( + columns: 2, + column-gutter: 3cm, + align: top, + grid( + columns: 2, + column-gutter: 1cm, + row-gutter: 5mm, + align: left+top, + [`init(4,0,0)`], ringbuf(([], [], [], []), 0, 0), pause, + [`put(3)`], ringbuf((3, [], [], []), 1, 0), pause, + [`put(5)`], ringbuf((3, 5, [], []), 2, 0), pause, + [`put(7)`], ringbuf((3, 5, 7, []), 3, 0), pause, + [`get()→3`], ringbuf((3, 5, 7, []), 3, 1), pause, + [`put(11)`], ringbuf((3, 5, 7, 11), 0, 1), pause, + ), + [ + #grid( + columns: 2, + column-gutter: 1cm, + row-gutter: 5mm, + align: left+top, + [`put(13)`], ringbuf((13, 5, 7, 11), 1, 1), pause, + [`put(17)`], [???] + ) + #pause + #v(1cm) + Plusieurs choix possibles selon l'implémentation ! + - `put` renvoie une erreur : le buffer est plein. + - `put` bloque jusqu'à ce que `5` soit récupéré. + - `put` écrase `5`.#h(1cm) #box(baseline: 100%, inset: (top: -5mm), ringbuf((13, 17, 7, 11), 2, 1)) + ], +) + +== Pseudocode d'implémentation — variante _écrase_ +```py +N = 4 +buf = [0, 0, 0, 0] +w = 0 +r = 0 + +def put(elem): + buf[w] = elem + w = (w + 1) % N + +def get(): + val = buf[r] + r = (r + 1) % N + return val +```