Skip to content

plain old C, to be called via ctypesΒ #4

@jsbueno

Description

@jsbueno

we can format this a sa pr later, but it is this thing:

unsigned long long count_double(char *str) {
    char *i, c1, c2;
    unsigned long long  count = 0;

    c1 = *str;
    c2 = *(str + 1);
    for(i = str+1; c2 = *i; i++) {
        count += (c1 == c2);
        c1 = c2;
    }
    return count;
}

Build with:
gcc -shared -o libblacount.so -fPIC blacount.c

And prepare to use from Python with:

import ctypes
blacount = ctypes.cdll.LoadLibrary("./libblacount.so")
blacount.count_double.argtypes = [ctypes.c_char_p]
blacount.count_double.restype = ctypes.c_uint64

(it counts byte-strings only)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions