bcaa 0.0.1

Simple associative array implementation for D (-betterC)


To use this package, run the following command in your project's root directory:

Manual usage
Put the following dependency into your project's dependences section:

bcaa

Simple associative array implementation for D (-betterC).

  • compatible with betterC.
  • similar to built-in AA (some codes were borrowed from druntime and DMD).
  • memory management using malloc and free.
  • supported key types: string and integral types.

Examples:

    import core.stdc.stdio;
    import core.stdc.time;

    clock_t begin = clock();

    Bcaa!(int, int) aa0;

    foreach (i; 0..1000000){
        aa0[i] = i;
    }

    foreach (i; 2000..1000000){
        aa0.remove(i);
    }

    printf("%d \n", aa0[1000]);
    aa0.free;

    clock_t end = clock(); printf("Elapsed time: %f \n", cast(double)(end - begin) / CLOCKS_PER_SEC);

    Bcaa!(string, string) aa1;

    aa1["Stevie"] = "Ray Vaughan";
    aa1["Asım Can"] = "Gündüz";
    aa1["Dan"] = "Patlansky";
    aa1["İlter"] = "Kurcala";
    aa1["Ferhat"] = "Kurtulmuş";

    if (auto valptr = "Dan" in aa1)
        printf("%s exists!!!!\n", (*valptr).ptr );
    else
        printf("does not exist!!!!\n".ptr);

    assert(aa1.remove("Ferhat") == true);
    assert(aa1["Ferhat"] == null);
    assert(aa1.remove("Foe") == false);
    assert(aa1["İlter"] =="Kurcala");

    aa1.rehash();

    printf("%s\n",aa1["Stevie"].ptr);
    printf("%s\n",aa1["Asım Can"].ptr);
    printf("%s\n",aa1["Dan"].ptr);
    printf("%s\n",aa1["Ferhat"].ptr);

    auto keys = aa1.keys;
    foreach(key; keys)
        printf("%s -> %s \n", key.ptr, aa1[key].ptr);
    core.stdc.stdlib.free(keys.ptr);
    aa1.free;

    struct Guitar {
        string brand;
    }

    Bcaa!(int, Guitar) guitars;

    guitars[0] = Guitar("Fender");
    guitars[3] = Guitar("Gibson");
    guitars[356] = Guitar("Stagg");

    assert(guitars[3].brand == "Gibson");

    printf("%s \n", guitars[356].brand.ptr);

    if(auto valPtr = 3 in guitars)
        printf("%s \n", (*valPtr).brand.ptr);

    guitars.free;

Authors:
  • Ferhat Kurtulmuş
Dependencies:
none
Versions:
0.0.9 2022-Mar-22
0.0.8 2021-Oct-20
0.0.7 2021-Jul-09
0.0.6 2021-Mar-05
0.0.5 2021-Jan-12
Show all 8 versions
Download Stats:
  • 15 downloads today

  • 98 downloads this week

  • 447 downloads this month

  • 10157 downloads total

Score:
4.0
Short URL:
bcaa.dub.pm