i've been programming in PHP for around 15 years. i suppose that might make me a bit of a PHP guru. unfortunately, during my hiatus from true compiled languages, my C and C++ coding had gotten a bit rusty. i had definitely done some recent coding in C to modify my personal version of the open source DJ mixing software
mixxx, but only a small hack to change the way that the fader position was mapped to the output volume for two music tracks.
i'm working on a project that compares N files of about 40,000 rows to each other and does some analysis and stores it in a database table. the PHP version was obviously slow. i was able to create logic that reduced the comparison of 3 files to about 3 hours on a moderately old system 7-8 years old with maybe 8 cores. speedup was only going to be possible by rewriting in a non-realtime-compiled language.
i discovered the
libdbi libraries and started down a road paved with errors about illegal type conversions since typed languages haven't been on my mind for a while.
as i got started i realized that there was one problem. i NEEDED associative arrays.
in PHP, associative arrays allow you to set up arrays like this:
$people[0]["fname"] = "bob";
$people[0]["lname"] = "marley";
$people[1]["fname"] = "bob";
$people[1]["lname"] = "dylan";
...allowing you to reference each element by an index (here, 0 or 1) and the strings "fname" or "lname".
as one might guess, this is an excellent programmatic way of dealing with large sets of data like those returned from a database query or imported from a CSV file where you want to associate a bunch of rows that you would like to reference with an integer index storing column names and values.
after doing a little bit of research and some wild-goose chasing, i found a good solution to the lack of this specific functionality being included by default in C.
maps.
// declare the map. NOTE: the space between the ">" characters seems to be crucial,
// otherwise there are compilation errors
map
> result;
result[0]["fname"]="bob";
cout << result[0]["fname"] << endl; // prints "bob" to stdout
now i just have to finish writing these database wrapper functions to simplify the coding for my project a little. :)