💾 Archived View for gmi.noulin.net › gitRepositories › set › file › main.c.gmi captured on 2024-07-09 at 02:42:35. Gemini links have been rewritten to link to archived content

View Raw

More Information

⬅️ Previous capture (2023-01-29)

-=-=-=-=-=-=-

set

Log

Files

Refs

LICENSE

main.c (2838B)

     1 #! /usr/bin/env sheepy
     2 /* or direct path to sheepy: #! /usr/local/bin/sheepy */
     3 
     4 /* Libsheepy documentation: http://spartatek.se/libsheepy/ */
     5 #include "libsheepyObject.h"
     6 #include "set.h"
     7 
     8 // hash functions for the hash table
     9 #include "shpPackages/hashfunctions/hashfunctions.h"
    10 
    11 int argc; char **argv;
    12 
    13 /* enable/disable logging */
    14 /* #undef pLog */
    15 /* #define pLog(...) */
    16 
    17 int main(int ARGC, char** ARGV) {
    18 
    19   argc = ARGC; argv = ARGV;
    20 
    21   initLibsheepy(ARGV[0]);
    22   setLogMode(LOG_VERBOSE);
    23 
    24   sstaticSetT(sst, u8, 5);
    25 
    26   sst st;
    27 
    28   sstaticSetClear(&st);
    29 
    30   #undef HASHFUNC
    31   #undef ISEMPTY
    32   #undef CMPFUNC
    33   #define HASHFUNC(k) k
    34   #define ISEMPTY(e) (e == 0)
    35   #define CMPFUNC(e1, e2) (e1 == e2)
    36 
    37   var idx = sstaticSetGetNAdd(&st, 1);
    38   logVarG(idx);
    39   idx = sstaticSetGetNAdd(&st, 3);
    40   logVarG(idx);
    41   logI("get: %zd", sstaticSetGet(&st, 3));
    42   logI("get: %zd", sstaticSetGet(&st, 2));
    43   logI("has: %b", sstaticSetHas(&st, 3));
    44   logI("has: %b", sstaticSetHas(&st, 2));
    45   idx = sstaticSetGetNAdd(&st, 12);
    46   logVarG(idx);
    47   idx = sstaticSetGetNAdd(&st, 2);
    48   logVarG(idx);
    49   idx = sstaticSetAdd(&st, 22);
    50   logVarG(idx);
    51   idx = sstaticSetAdd(&st, 2);
    52   logVarG(idx);
    53   idx = sstaticSetGetNAdd(&st, 4);
    54   logVarG(idx);
    55   logI("get: %zd", sstaticSetGet(&st, 3));
    56   logI("get: %zd", sstaticSetGet(&st, 2));
    57   logI("get: %zd", sstaticSetGet(&st, 32));
    58   logI("has: %b", sstaticSetHas(&st, 3));
    59   logI("has: %b", sstaticSetHas(&st, 2));
    60   logI("has: %b", sstaticSetHas(&st, 32));
    61 
    62 
    63   #undef HASHFUNC
    64   #undef ISEMPTY
    65   #undef CMPFUNC
    66   // hash function for cs
    67   #define HASHFUNC strHashFNV1A
    68   // comparison function for cs
    69   //#define CMPFUNC !strcmp
    70   #define CMPFUNC eqS
    71 
    72   astaticSetT(cst, char*, 5);
    73   cst cs;
    74 
    75   astaticSetClear(&cs);
    76 
    77   range(i, 5) {
    78     logVarG(cs.set[i]);
    79   }
    80 
    81   var ix = astaticSetGetNAdd(&cs, "1");
    82   logVarG(ix);
    83   ix = astaticSetGetNAdd(&cs, "3");
    84   logVarG(ix);
    85   logI("get: 3 - %zd", astaticSetGet(&cs, "3"));
    86   logI("get: 2 - %zd", astaticSetGet(&cs, "2"));
    87   logI("has: %b", astaticSetHas(&cs, "3"));
    88   logI("has: %b", astaticSetHas(&cs, "2"));
    89   ix = astaticSetGetNAdd(&cs, "12");
    90   logI("12: %zd", ix);
    91   ix = astaticSetGetNAdd(&cs, "2");
    92   logI("2: %zd", ix);
    93   ix = astaticSetAdd(&cs, "22");
    94   logI("add 22: %zd (1=ok)", ix);
    95   ix = astaticSetAdd(&cs, "2");
    96   logVarG(ix);
    97   ix = astaticSetGetNAdd(&cs, "4");
    98   logVarG(ix);
    99   logI("get: 3  %zd", astaticSetGet(&cs, "3"));
   100   logI("get: 2  %zd", astaticSetGet(&cs, "2"));
   101   logI("get: 22 %zd", astaticSetGet(&cs, "22"));
   102   logI("get: 32 %zd", astaticSetGet(&cs, "32"));
   103   logI("has: 3  %b", astaticSetHas(&cs, "3"));
   104   logI("has: 2  %b", astaticSetHas(&cs, "2"));
   105   logI("has: 32 %b", astaticSetHas(&cs, "32"));
   106 
   107   range(i, 5) {
   108     logVarG(astaticSetAt(&cs, i));
   109   }
   110 
   111   logVarG(sizeof st);
   112   logVarG(sizeof cs);
   113 }
   114 // vim: set expandtab ts=2 sw=2: