github.com/moontrade/nogc@v0.1.7/collections/wormhole/wh.h (about)

     1  /*
     2   * Copyright (c) 2016--2021  Wu, Xingbo <wuxb45@gmail.com>
     3   *
     4   * All rights reserved. No warranty, explicit or implicit, provided.
     5   */
     6  #pragma once
     7  
     8  #ifdef __cplusplus
     9  extern "C" {
    10  #endif
    11  
    12  struct wormhole;
    13  struct wormref;
    14  
    15  // wormhole {{{
    16  // the wh created by wormhole_create() can work with all of safe/unsafe operations.
    17    extern struct wormhole *
    18  wormhole_create(const struct kvmap_mm * const mm);
    19  
    20  // the wh created by whunsafe_create() can only work with the unsafe operations.
    21    extern struct wormhole *
    22  whunsafe_create(const struct kvmap_mm * const mm);
    23  
    24    extern struct kv *
    25  wormhole_get(struct wormref * const ref, const struct kref * const key, struct kv * const out);
    26  
    27    extern bool
    28  wormhole_probe(struct wormref * const ref, const struct kref * const key);
    29  
    30    extern bool
    31  wormhole_put(struct wormref * const ref, struct kv * const kv);
    32  
    33    extern bool
    34  wormhole_merge(struct wormref * const ref, const struct kref * const kref,
    35      kv_merge_func uf, void * const priv);
    36  
    37    extern bool
    38  wormhole_inpr(struct wormref * const ref, const struct kref * const key,
    39      kv_inp_func uf, void * const priv);
    40  
    41    extern bool
    42  wormhole_inpw(struct wormref * const ref, const struct kref * const key,
    43      kv_inp_func uf, void * const priv);
    44  
    45    extern bool
    46  wormhole_del(struct wormref * const ref, const struct kref * const key);
    47  
    48    extern u64
    49  wormhole_delr(struct wormref * const ref, const struct kref * const start,
    50      const struct kref * const end);
    51  
    52    extern struct wormhole_iter *
    53  wormhole_iter_create(struct wormref * const ref);
    54  
    55    extern void
    56  wormhole_iter_seek(struct wormhole_iter * const iter, const struct kref * const key);
    57  
    58    extern bool
    59  wormhole_iter_valid(struct wormhole_iter * const iter);
    60  
    61    extern struct kv *
    62  wormhole_iter_peek(struct wormhole_iter * const iter, struct kv * const out);
    63  
    64    extern bool
    65  wormhole_iter_kref(struct wormhole_iter * const iter, struct kref * const kref);
    66  
    67    extern bool
    68  wormhole_iter_kvref(struct wormhole_iter * const iter, struct kvref * const kvref);
    69  
    70    extern void
    71  wormhole_iter_skip1(struct wormhole_iter * const iter);
    72  
    73    extern void
    74  wormhole_iter_skip(struct wormhole_iter * const iter, const u32 nr);
    75  
    76    extern struct kv *
    77  wormhole_iter_next(struct wormhole_iter * const iter, struct kv * const out);
    78  
    79    extern bool
    80  wormhole_iter_inp(struct wormhole_iter * const iter, kv_inp_func uf, void * const priv);
    81  
    82    extern void
    83  wormhole_iter_park(struct wormhole_iter * const iter);
    84  
    85    extern void
    86  wormhole_iter_destroy(struct wormhole_iter * const iter);
    87  
    88    extern struct wormref *
    89  wormhole_ref(struct wormhole * const map);
    90  
    91    extern struct wormhole *
    92  wormhole_unref(struct wormref * const ref);
    93  
    94    extern void
    95  wormhole_park(struct wormref * const ref);
    96  
    97    extern void
    98  wormhole_resume(struct wormref * const ref);
    99  
   100    extern void
   101  wormhole_refresh_qstate(struct wormref * const ref);
   102  
   103  // clean with more threads
   104    extern void
   105  wormhole_clean_th(struct wormhole * const map, const u32 nr_threads);
   106  
   107    extern void
   108  wormhole_clean(struct wormhole * const map);
   109  
   110    extern void
   111  wormhole_destroy(struct wormhole * const map);
   112  
   113  // safe API (no need to refresh qstate)
   114  
   115    extern struct kv *
   116  whsafe_get(struct wormref * const ref, const struct kref * const key, struct kv * const out);
   117  
   118    extern bool
   119  whsafe_probe(struct wormref * const ref, const struct kref * const key);
   120  
   121    extern bool
   122  whsafe_put(struct wormref * const ref, struct kv * const kv);
   123  
   124    extern bool
   125  whsafe_merge(struct wormref * const ref, const struct kref * const kref,
   126      kv_merge_func uf, void * const priv);
   127  
   128    extern bool
   129  whsafe_inpr(struct wormref * const ref, const struct kref * const key,
   130      kv_inp_func uf, void * const priv);
   131  
   132    extern bool
   133  whsafe_inpw(struct wormref * const ref, const struct kref * const key,
   134      kv_inp_func uf, void * const priv);
   135  
   136    extern bool
   137  whsafe_del(struct wormref * const ref, const struct kref * const key);
   138  
   139    extern u64
   140  whsafe_delr(struct wormref * const ref, const struct kref * const start,
   141      const struct kref * const end);
   142  
   143  // use wormhole_iter_create
   144    extern void
   145  whsafe_iter_seek(struct wormhole_iter * const iter, const struct kref * const key);
   146  
   147    extern struct kv *
   148  whsafe_iter_peek(struct wormhole_iter * const iter, struct kv * const out);
   149  
   150  // use wormhole_iter_valid
   151  // use wormhole_iter_peek
   152  // use wormhole_iter_kref
   153  // use wormhole_iter_kvref
   154  // use wormhole_iter_skip1
   155  // use wormhole_iter_skip
   156  // use wormhole_iter_next
   157  // use wormhole_iter_inp
   158  
   159    extern void
   160  whsafe_iter_park(struct wormhole_iter * const iter);
   161  
   162    extern void
   163  whsafe_iter_destroy(struct wormhole_iter * const iter);
   164  
   165    extern struct wormref *
   166  whsafe_ref(struct wormhole * const map);
   167  
   168  // use wormhole_unref
   169  
   170  // unsafe API
   171  
   172    extern struct kv *
   173  whunsafe_get(struct wormhole * const map, const struct kref * const key, struct kv * const out);
   174  
   175    extern bool
   176  whunsafe_probe(struct wormhole * const map, const struct kref * const key);
   177  
   178    extern bool
   179  whunsafe_put(struct wormhole * const map, struct kv * const kv);
   180  
   181    extern bool
   182  whunsafe_merge(struct wormhole * const map, const struct kref * const kref,
   183      kv_merge_func uf, void * const priv);
   184  
   185    extern bool
   186  whunsafe_inp(struct wormhole * const map, const struct kref * const key,
   187      kv_inp_func uf, void * const priv);
   188  
   189    extern bool
   190  whunsafe_del(struct wormhole * const map, const struct kref * const key);
   191  
   192    extern u64
   193  whunsafe_delr(struct wormhole * const map, const struct kref * const start,
   194      const struct kref * const end);
   195  
   196    extern struct wormhole_iter *
   197  whunsafe_iter_create(struct wormhole * const map);
   198  
   199    extern void
   200  whunsafe_iter_seek(struct wormhole_iter * const iter, const struct kref * const key);
   201  
   202  // unsafe iter_valid: use wormhole_iter_valid
   203  // unsafe iter_peek: use wormhole_iter_peek
   204  // unsafe iter_kref: use wormhole_iter_kref
   205  
   206    extern void
   207  whunsafe_iter_skip1(struct wormhole_iter * const iter);
   208  
   209    extern void
   210  whunsafe_iter_skip(struct wormhole_iter * const iter, const u32 nr);
   211  
   212    extern struct kv *
   213  whunsafe_iter_next(struct wormhole_iter * const iter, struct kv * const out);
   214  
   215  // unsafe iter_inp: use wormhole_iter_inp
   216  
   217    extern void
   218  whunsafe_iter_destroy(struct wormhole_iter * const iter);
   219  
   220    extern void
   221  wormhole_fprint(struct wormhole * const map, FILE * const out);
   222  
   223  extern const struct kvmap_api kvmap_api_wormhole;
   224  extern const struct kvmap_api kvmap_api_whsafe;
   225  extern const struct kvmap_api kvmap_api_whunsafe;
   226  // }}} wormhole
   227  
   228  // wh {{{
   229    extern struct wormhole *
   230  wh_create(void);
   231  
   232    extern struct wormref *
   233  wh_ref(struct wormhole * const wh);
   234  
   235    extern void
   236  wh_unref(struct wormref * const ref);
   237  
   238    extern void
   239  wh_park(struct wormref * const ref);
   240  
   241    extern void
   242  wh_resume(struct wormref * const ref);
   243  
   244    extern void
   245  wh_clean(struct wormhole * const map);
   246  
   247    extern void
   248  wh_destroy(struct wormhole * const map);
   249  
   250    extern bool
   251  wh_put(struct wormref * const ref, const void * const kbuf, const u32 klen,
   252      const void * const vbuf, const u32 vlen);
   253  
   254    extern bool
   255  wh_del(struct wormref * const ref, const void * const kbuf, const u32 klen);
   256  
   257    extern bool
   258  wh_probe(struct wormref * const ref, const void * const kbuf, const u32 klen);
   259  
   260    extern bool
   261  wh_get(struct wormref * const ref, const void * const kbuf, const u32 klen,
   262      void * const vbuf_out, const u32 vbuf_size, u32 * const vlen_out);
   263  
   264    extern bool
   265  wh_inpr(struct wormref * const ref, const void * const kbuf, const u32 klen,
   266      kv_inp_func uf, void * const priv);
   267  
   268    extern bool
   269  wh_inpw(struct wormref * const ref, const void * const kbuf, const u32 klen,
   270      kv_inp_func uf, void * const priv);
   271  
   272    extern bool
   273  wh_merge(struct wormref * const ref, const void * const kbuf, const u32 klen,
   274      kv_merge_func uf, void * const priv);
   275  
   276    extern u64
   277  wh_delr(struct wormref * const ref, const void * const kbuf_start, const u32 klen_start,
   278      const void * const kbuf_end, const u32 klen_end);
   279  
   280    extern struct wormhole_iter *
   281  wh_iter_create(struct wormref * const ref);
   282  
   283    extern void
   284  wh_iter_seek(struct wormhole_iter * const iter, const void * const kbuf, const u32 klen);
   285  
   286    extern bool
   287  wh_iter_valid(struct wormhole_iter * const iter);
   288  
   289    extern bool
   290  wh_iter_peek(struct wormhole_iter * const iter,
   291      void * const kbuf_out, const u32 kbuf_size, u32 * const klen_out,
   292      void * const vbuf_out, const u32 vbuf_size, u32 * const vlen_out);
   293  
   294    extern void
   295  wh_iter_skip1(struct wormhole_iter * const iter);
   296  
   297    extern void
   298  wh_iter_skip(struct wormhole_iter * const iter, const u32 nr);
   299  
   300    extern bool
   301  wh_iter_inp(struct wormhole_iter * const iter, kv_inp_func uf, void * const priv);
   302  
   303    extern void
   304  wh_iter_park(struct wormhole_iter * const iter);
   305  
   306    extern void
   307  wh_iter_destroy(struct wormhole_iter * const iter);
   308  // }}} wh
   309  
   310  #ifdef __cplusplus
   311  }
   312  #endif
   313  // vim:fdm=marker