Advent of Code

Check-in [d59f9c2e2f]
Login

Check-in [d59f9c2e2f]

Overview
Comment:TextGrid looks ok
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | TextGrid
Files: files | file ages | folders
SHA3-256: d59f9c2e2f7754a0c6ce8b3c4c5dd60c47efc03055ac349d5a6f9d5b18c81698
User & Date: nnz on 2024-12-08 13:52:25
Other Links: branch diff | manifest | tags
Context
2024-12-08
13:53
added test file check-in: 85a490fa64 user: nnz tags: TextGrid
13:52
TextGrid looks ok check-in: d59f9c2e2f user: nnz tags: TextGrid
13:25
removed extra stuff check-in: 85dc24a9dc user: nnz tags: TextGrid
Changes

Modified aocutils.c from [a12f3ca546] to [a7eed73da2].

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include <stbool.h>
#include <stdio.h>
#include <stdlib.h>
#include "aocutils.h"

struct TextGrid {
    unsigned rows, cols;
    char *data; // may have '\n' at end of rows
};

bool TGvalid(struct TextGrid *tg, unsigned row, unsigned col) {
    if (row >= tg->rows) return false;
    if (col >= tg->cols) return false;
    return true;
}
char *TGcharptr(struct TextGrid *tg, unsigned row, unsigned col) {
    if (row >= tg->rows) return NULL;
    if (col >= tg->cols) return NULL;
    return data + (row * tg->cols) + col;
}

// TODO: rewrite this shit
size_t linearize2d(unsigned width, unsigned row, unsigned col) {
    return (row * width) + col;
}

|




<
<
<
<
<






|
<
|







1
2
3
4
5





6
7
8
9
10
11
12

13
14
15
16
17
18
19
20
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include "aocutils.h"






bool TGvalid(struct TextGrid *tg, unsigned row, unsigned col) {
    if (row >= tg->rows) return false;
    if (col >= tg->cols) return false;
    return true;
}
char *TGcharptr(struct TextGrid *tg, unsigned row, unsigned col) {
    if (!TGvalid(tg, row, col)) return NULL;

    return tg->data + (row * tg->cols) + col;
}

// TODO: rewrite this shit
size_t linearize2d(unsigned width, unsigned row, unsigned col) {
    return (row * width) + col;
}