dvector 0.0.1

Simple dynamic 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:

dvector

Simple dynamic array implementation for D that fits my needs.

  • compatible with betterC.
  • don't expect much, but it does the things :)
  • Tested in ballgame.

Example:

import core.stdc.stdlib;
import core.stdc.stdio;

import dvector;

T* mallocOne(T, Args...)(Args args) nothrow @nogc{
    T* p = cast(T*)malloc(T.sizeof);
    *p = T(args);
    return p;
} 

void freeALL(T)(T arr) nothrow @nogc{
    foreach(elem; arr){
        free(elem);
    }
    arr.free();
}

struct Person {
    string name;
    uint score;
}

int main() nothrow @nogc
{
    Dvector!(Person*) prs1; prs1._init_;
    
    auto p1 = mallocOne!Person("ferhat", 5);
    auto p2 = mallocOne!Person("Mike", 3);
    auto p3 = mallocOne!Person("Rajneesh", 1);
    auto p4 = mallocOne!Person("Ce", 2);
    
    prs1 = prs1 ~ p1;
    prs1 ~= p2;
    prs1 ~= p3;
    prs1 ~= p4;

    Dvector!(Person*) prs2; prs2._init_;
    auto s1 = mallocOne!Person("Ezgi", 15);
    auto s2 = mallocOne!Person("Emine", 36);
    
    prs2 ~= s1;
    prs2 ~= s2;
    
    auto comb = prs1 ~ prs2;
    freeALL(prs2);
    
    comb.remove(2);
    
    assert(comb[2].name == "Ce");
    
    auto cn = mallocOne!Person("Chuck", 100);
    comb.pFront(cn);
    
    assert(comb[0].name == "Chuck");
    
    auto srv = mallocOne!Person("SRV", 100);
    comb.insert(srv, 3);
    
    assert(comb[3].name == "SRV");
    
    foreach(i, p; comb){
        printf("%d: %s \n", i, p.name.ptr);
    }
    
    freeALL(comb);
    return 0;
}
Authors:
  • Ferhat Kurtulmuş
Dependencies:
none
Versions:
0.0.5 2020-Mar-20
0.0.4 2020-Feb-25
0.0.3 2020-Feb-11
0.0.2 2019-Nov-12
0.0.1 2019-Sep-01
Show all 5 versions
Download Stats:
  • 0 downloads today

  • 0 downloads this week

  • 5 downloads this month

  • 578 downloads total

Score:
1.6
Short URL:
dvector.dub.pm