diff options
| author | Mitja Felicijan <mitja.felicijan@gmail.com> | 2023-11-09 23:19:53 +0100 |
|---|---|---|
| committer | Mitja Felicijan <mitja.felicijan@gmail.com> | 2023-11-09 23:19:53 +0100 |
| commit | 1566b6faa8534118c3566188181367cd0868468f (patch) | |
| tree | 1de8d4b369efb5e592685a31088f798a6b63ffa1 /examples/dte/block.h | |
| parent | 349991bf6efe473ab9a5cbdae0a8114d72b997e3 (diff) | |
| download | crep-1566b6faa8534118c3566188181367cd0868468f.tar.gz | |
Added partial matching and introduced threads
Diffstat (limited to 'examples/dte/block.h')
| -rw-r--r-- | examples/dte/block.h | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/examples/dte/block.h b/examples/dte/block.h new file mode 100644 index 0000000..6fbf361 --- /dev/null +++ b/examples/dte/block.h @@ -0,0 +1,39 @@ +#ifndef BLOCK_H +#define BLOCK_H + +#include <stddef.h> +#include "util/list.h" +#include "util/macros.h" + +enum { + BLOCK_ALLOC_MULTIPLE = 64 +}; + +// Blocks always contain whole lines. +// There's one zero-sized block for an empty file. +// Otherwise zero-sized blocks are forbidden. +typedef struct { + ListHead node; + unsigned char NONSTRING *data; + size_t size; + size_t alloc; + size_t nl; +} Block; + +#define block_for_each(block_, list_head_) \ + for ( \ + block_ = BLOCK((list_head_)->next); \ + &block_->node != (list_head_); \ + block_ = BLOCK(block_->node.next) \ + ) + +static inline Block *BLOCK(ListHead *item) +{ + static_assert(offsetof(Block, node) == 0); + return (Block*)item; +} + +Block *block_new(size_t alloc) RETURNS_NONNULL; +void block_free(Block *blk) NONNULL_ARGS; + +#endif |
