Random commentary about Machine Learning, BigData, Spark, Deep Learning, C++, STL, Boost, Perl, Python, Algorithms, Problem Solving and Web Search
Friday, January 9, 2009
Generic Skip list (skiplist)
Skip lists are an interesting randomize data structure for storing pairs of . Skip lists have logaritmic search and insertion time. Here I sketch a generic skip list code
The right grammar should be that "skip lists are a ..."
ReplyDeletemore precisely: "are an interesting"
ReplyDeleteif ((tk == 0) || // null?
ReplyDelete( key < tk->key_)) // search key < next level link's key
Is not correct. C++ does not guarantee left to right evaluation and so this may result in a segmentation fault depending on the compiler.
@anonymous:
ReplyDeleteof course it does for && and ||: it is called shortcut evaluation, and test for null OR dereference is idiomatic both in C and C++.
I believe you have a bug in your search__ function:
ReplyDeleteif ((x == 0)) ||
(key < x->val_))
Shouldn't this read:
if ((x == 0)) ||
(key < x->key_))
?