In C programming, the main difference between low-level I/O functions (open/close/read/write) and stream-level I/O functions (fopen/fclose/fread/fwrite) is that stream-level functions are buffered. Presumably, low-level I/O functions will incur a disk operation on each read(). Although the kernel may cache this, we cannot rely too much on it. Disk operations are expensive and so low-level I/O [...]
Posts Tagged ‘myprog’
A Generic Buffered Stream Wrapper
Posted in development, tagged C, myprog on October 11, 2008 | Leave a Comment »
Another Look at my old Benchmark
Posted in development, tagged benchmark, C, cpp, myprog, programming on October 7, 2008 | 24 Comments »
This is a follow-up of my previous post. Here I change the table to several charts. Hope it seems more friendly to readers. You can find the links to these libraries in that table. Their source codes, including my testing code, are available here. You may also want to see my previous posts in the [...]
Futher Discussion on Search Trees
Posted in development, tagged benchmark, C, cpp, myprog, programming on September 28, 2008 | Leave a Comment »
Over the weekend, I have done a more comprehensive benchmark of various libraries on search trees. Two AVL, seven red-black tree, one Splay tree, two treap implementations are involved, together with seven hash table libraries. As I need to present a big table, I have to write it in a free-style HTML page. You can [...]
B-tree vs. Binary Search Tree
Posted in development, tagged C, myprog, programming on September 24, 2008 | 18 Comments »
When talking about in-memory search tree, we usually think of various binary search trees: red-black tree, AVL tree, treap, splay tree and so on. We do not often think of B-tree, as B-tree is commonly introduced as an on-disk data structure rather than in-memory one. Is B-tree also a good data structure for in-memory ordered [...]
A Simple Generic Vector Container in C
Posted in development, tagged C, macro, myprog, programming on September 22, 2008 | 3 Comments »
I do not see much need to have a vector container in C as a vector is simply an array and array operations are all very simple. Nontheless, it might still better to implement one, for the sake of completeness. Here is the code. The library is almost as fast as the fastest code you [...]
Calculating Median
Posted in development, tagged algorithm, C, myprog, programming on September 13, 2008 | Leave a Comment »
Here is an example that google does not give me the result in the first page. I want to know how to calculate median efficiently, and so I search “c calculate median”. In the first result page, google brings me to several forums which only show very naive implementations. The 11th result, this page, is [...]
Implementing Generic Hash Library in C
Posted in development, tagged C, hash, myprog, programming on September 2, 2008 | 9 Comments »
Synopsis
Here is an simple example showing how to use khash.h library:
#include "khash.h"
KHASH_MAP_INIT_INT(32, char)
int main() {
int ret, is_missing;
khiter_t k;
khash_t(32) *h = kh_init(32);
k = kh_put(32, h, 5, &ret);
if (!ret) kh_del(32, h, k);
kh_value(h, k) = 10;
k = kh_get(32, h, 10);
is_missing = (k == kh_end(h));
k = kh_get(32, h, 5);
kh_del(32, h, k);
for (k = kh_begin(h); k != kh_end(h); ++k)
if (kh_exist(h, [...]
Comparison of Hash Table Libraries
Posted in development, tagged benchmark, C, cpp, hash, myprog, programming on August 28, 2008 | 25 Comments »
As a Perl programmer, I enjoy a lot using hash tables. I keep this habit in C/C++ programming. Then what C/C++ hash libraries are available? How are they compared to each other? In this post, I will give a brief review of hash libraries and present a small benchmark showing their practical performance.
Hash table libraries
In [...]
Comparison of Internal Sorting Algorithms
Posted in development, tagged algorithm, benchmark, cpp, myprog, programming on August 28, 2008 | 2 Comments »
Sorting algorithm
Given an array of size N, sorting can be done in O(N log(N)) in average. The most frequently used sorting algorithms that can achieve this time complexity are quicksort, heapsort and mergesort. They usually require O(log(N)), O(1) and O(N) working space, respectively (the space complexity of mergesort can be improved at the cost of [...]
Derivative-Free Optimization (DFO)
Posted in research, tagged cpp, mathematics, myprog, programming on August 24, 2008 | Leave a Comment »
You can find good subroutines in GSL for multivariable nonlinear optimization, but the only method it provides for DFO is Nelder-Mead simplex method, which, claimed by Numerical Recipes, is “almost surely” slower than the Powell’s direct set method “in all likely applications”. You can find some DFO solvers here, but few of them are implemented [...]