<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -144,7 +144,7 @@ module StrokeDB
       return first ? first[1] : nil
     end
     
-    # Insert a key-value pair. If key already exists,
+    # Insert a key-value pair. If the key already exists,
     # value will be overwritten.
     #
     #  &lt;i&gt; is a new node
@@ -179,6 +179,36 @@ module StrokeDB
     	self
   	end
   	
+  	# Remove a key-value pair. If the key does not exist,
+    # no action is performed.
+    #
+    #  &lt;d&gt; is a node to be removed
+    #  &lt;M&gt; is a marked node in a update_list
+    #  &lt;N&gt; is next node to &lt;M&gt; which reference must be updated. 
+    #
+    #  M-----------------&gt; d &lt;---------------- N ...
+    #  o ------&gt; M ------&gt; d &lt;------ N ... 
+    #  o -&gt; o -&gt; o -&gt; M -&gt; d &lt;- N ....
+    #
+    def delete(key)
+      @mutex.synchronize do
+        x = anchor
+        level = node_level(x)
+        update = Array.new(level)
+        x = find_with_update(x, level, key, update)
+        
+        # remove existing key
+  	    if node_compare(x, key) == 0
+  	      level = node_level(x)
+  	      while level &gt; 0
+  	        level -= 1
+  	        node_delete_after!(x, update[level], level)
+          end
+    	  end
+      end
+    	self
+  	end
+  	
   	def find_with_update(x, level, key, update) #:nodoc:
   	  while level &gt; 0
         level -= 1
@@ -421,6 +451,25 @@ module StrokeDB
       netx[3][level] = x
     end
     
+    # before: 
+    #   prev -&gt; x -&gt; next
+    #   prev &lt;- x -&gt; next
+    #
+    # after:
+    #
+    #  prev -&gt; next
+    #  prev &lt;- next
+    #
+    def node_delete_after!(x, prev, level)
+      netx = node_next(x, level)  # 'next' is a reserved word in ruby
+      
+      # forward links
+      prev[0][level] = netx
+      
+      # backward links
+      netx[3][level] = prev
+    end
+    
     def new_node(level, key, value)
       [ 
         [nil]*level, </diff>
      <filename>lib/strokedb/data_structures/simple_skiplist.rb</filename>
    </modified>
    <modified>
      <diff>@@ -98,6 +98,25 @@ SimpleSkiplist.with_optimizations(OPTIMIZATIONS) do |lang|
   end
 
 
+  describe &quot;Deleting from skiplist&quot; do
+    before(:each) do
+      @list = SimpleSkiplist.new
+      @list.insert &quot;1a&quot;, &quot;a&quot;
+      @list.insert &quot;1b&quot;, &quot;b&quot;
+      @list.insert &quot;1c&quot;, &quot;c&quot;
+      @list.insert &quot;1d&quot;, &quot;d&quot;
+    end
+    it &quot;should store nil&quot; do
+      @list.insert(&quot;1b&quot;, nil)
+      @list.search(&quot;1&quot;, &quot;1&quot;, 3, 0, false, false).should == [&quot;a&quot;, nil, &quot;c&quot;]
+    end
+    it &quot;should delete item&quot; do
+      @list.delete(&quot;1b&quot;)
+      @list.search(&quot;1&quot;, &quot;1&quot;, 3, 0, false, false).should == [&quot;a&quot;, &quot;c&quot;, &quot;d&quot;]
+    end
+  end
+
+
   describe &quot;Big skiplist [#{lang}]&quot; do
     before(:each) do
       @maxlevel    = 8</diff>
      <filename>spec/lib/strokedb/data_structures/simple_skiplist_spec.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>03795003ae925546efc24a45b3bb5047d76b6c36</id>
    </parent>
  </parents>
  <author>
    <name>Oleg Andreev</name>
    <email>oleganza@idbns.com</email>
  </author>
  <url>http://github.com/yrashk/strokedb/commit/70bd2f5d26937659ae299c333f890a6baece162a</url>
  <id>70bd2f5d26937659ae299c333f890a6baece162a</id>
  <committed-date>2008-05-24T13:48:35-07:00</committed-date>
  <authored-date>2008-05-24T13:48:35-07:00</authored-date>
  <message>added SimpleSkiplist#delete</message>
  <tree>9eb462feabb90124dec9c4f9327b6c0738139538</tree>
  <committer>
    <name>Oleg Andreev</name>
    <email>oleganza@idbns.com</email>
  </committer>
</commit>
