2020/12/17

2020/12/17

  • メルカリ発送
  • lambda

# releational

  • なんかあった

context.h

1
2
3
4
5
enum Relational {
    EQ,
    GT,
    LT,
};

compare.c

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
#include "context.h"

enum Relational compare(struct Node* node1, struct Node* node2) {
    int key1 = node1->key;
    int key2 = node2->key;
    if (key1 == key2) {
        return EQ;
    } else if (key1 < key2) {
        return GT;
    } else {
        return LT;
    }
}

見たところRbTreeで使おうとしていた痕跡がある

1
2
RedBlackTree.cbc
7:extern enum Relational compare(struct Node* node1, struct Node* node2);
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
__code putRedBlackTree(struct RedBlackTree* tree, struct Node* node) {
    struct Node* newNode = &ALLOCATE(context, Node)->Node;
    struct Node* root = tree->root;
    printTree((union Data*)(tree->root));
    tree->newNode = newNode;
    tree->root = newNode; // this should done at stackClear
    tree->parent = NULL;
    if (root) {
        tree->current = root;
        tree->result = compare(tree->current, node);
        tree->findNodeNext = C_insertNode;
        goto findNode(tree);
    }
    goto insertNode(tree, node);
}
  • Selfを導入
    • Typeを型クラスとして使いたい
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
typedef struct Tree<Self, Impl, Type>{
    /* future Code */
    /* Type* tree; */
    /* Type* node; */
    union Data* tree;
    struct Node* node;
    __code put(Impl* tree,Type* node, __code next(...));
    __code get(Impl* tree, __code next(...));
    __code remove(Impl* tree,Type* node, __code next(...));
    // __code clearRedBlackTree();
    __code next(...);
} Tree;

sdとrgを組み合わせる

1
$sd '<Type' '<Self' $(rg '<Type' -g '*.h' --files-with-matches)
Licensed under CC BY-NC-SA 4.0
comments powered by Disqus
Built with Hugo
Theme Stack designed by Jimmy