Junio C Hamano | a84b794 | 2013-04-13 11:56:41 -0700 | [diff] [blame] | 1 | #ifndef COMMIT_SLAB_H |
| 2 | #define COMMIT_SLAB_H |
| 3 | |
Nguyễn Thái Ngọc Duy | a9f1f1f | 2018-05-19 07:28:17 +0200 | [diff] [blame] | 4 | #include "commit-slab-decl.h" |
| 5 | #include "commit-slab-impl.h" |
| 6 | |
Junio C Hamano | a84b794 | 2013-04-13 11:56:41 -0700 | [diff] [blame] | 7 | /* |
| 8 | * define_commit_slab(slabname, elemtype) creates boilerplate code to define |
| 9 | * a new struct (struct slabname) that is used to associate a piece of data |
| 10 | * of elemtype to commits, and a few functions to use that struct. |
| 11 | * |
| 12 | * After including this header file, using: |
| 13 | * |
Ville Skyttä | 2e3a16b | 2016-08-09 11:53:38 +0300 | [diff] [blame] | 14 | * define_commit_slab(indegree, int); |
Junio C Hamano | a84b794 | 2013-04-13 11:56:41 -0700 | [diff] [blame] | 15 | * |
| 16 | * will let you call the following functions: |
| 17 | * |
| 18 | * - int *indegree_at(struct indegree *, struct commit *); |
| 19 | * |
| 20 | * This function locates the data associated with the given commit in |
Junio C Hamano | 862e730 | 2015-05-14 15:25:52 -0700 | [diff] [blame] | 21 | * the indegree slab, and returns the pointer to it. The location to |
| 22 | * store the data is allocated as necessary. |
| 23 | * |
| 24 | * - int *indegree_peek(struct indegree *, struct commit *); |
| 25 | * |
| 26 | * This function is similar to indegree_at(), but it will return NULL |
SZEDER Gábor | 7422b2a | 2020-03-10 16:30:49 +0100 | [diff] [blame] | 27 | * if the location to store the data associated with the given commit |
| 28 | * has not been allocated yet. |
| 29 | * Note that the location to store the data might have already been |
| 30 | * allocated even if no indegree_at() call has been made for that commit |
| 31 | * yet; in this case this function returns a pointer to a |
| 32 | * zero-initialized location. |
Junio C Hamano | a84b794 | 2013-04-13 11:56:41 -0700 | [diff] [blame] | 33 | * |
| 34 | * - void init_indegree(struct indegree *); |
| 35 | * void init_indegree_with_stride(struct indegree *, int); |
| 36 | * |
| 37 | * Initializes the indegree slab that associates an array of integers |
| 38 | * to each commit. 'stride' specifies how big each array is. The slab |
Thomas Rast | dcbbc8f | 2013-11-25 20:02:00 +0100 | [diff] [blame] | 39 | * that is initialized by the variant without "_with_stride" associates |
Junio C Hamano | a84b794 | 2013-04-13 11:56:41 -0700 | [diff] [blame] | 40 | * each commit with an array of one integer. |
Thomas Rast | dcbbc8f | 2013-11-25 20:02:00 +0100 | [diff] [blame] | 41 | * |
| 42 | * - void clear_indegree(struct indegree *); |
| 43 | * |
| 44 | * Empties the slab. The slab can be reused with the same stride |
| 45 | * without calling init_indegree() again or can be reconfigured to a |
| 46 | * different stride by calling init_indegree_with_stride(). |
| 47 | * |
| 48 | * Call this function before the slab falls out of scope to avoid |
| 49 | * leaking memory. |
SZEDER Gábor | 1df15f8 | 2020-06-05 13:00:26 +0000 | [diff] [blame] | 50 | * |
| 51 | * - void deep_clear_indegree(struct indegree *, void (*free_fn)(int*)) |
| 52 | * |
| 53 | * Empties the slab, similar to clear_indegree(), but in addition it |
| 54 | * calls the given 'free_fn' for each slab entry to release any |
| 55 | * additional memory that might be owned by the entry (but not the |
| 56 | * entry itself!). |
| 57 | * Note that 'free_fn' might be called even for entries for which no |
| 58 | * indegree_at() call has been made; in this case 'free_fn' is invoked |
| 59 | * with a pointer to a zero-initialized location. |
Junio C Hamano | a84b794 | 2013-04-13 11:56:41 -0700 | [diff] [blame] | 60 | */ |
| 61 | |
Nguyễn Thái Ngọc Duy | a9f1f1f | 2018-05-19 07:28:17 +0200 | [diff] [blame] | 62 | #define define_commit_slab(slabname, elemtype) \ |
| 63 | declare_commit_slab(slabname, elemtype); \ |
Nguyễn Thái Ngọc Duy | 878f0bb | 2018-05-19 07:28:18 +0200 | [diff] [blame] | 64 | implement_static_commit_slab(slabname, elemtype) |
Jeff King | 80cdaba | 2014-06-10 17:42:51 -0400 | [diff] [blame] | 65 | |
Junio C Hamano | a84b794 | 2013-04-13 11:56:41 -0700 | [diff] [blame] | 66 | #endif /* COMMIT_SLAB_H */ |