jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From thom...@apache.org
Subject svn commit: r1165315 - in /jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk: index/BTree.java index/BTreeLeaf.java index/IndexNode.java util/StringUtils.java
Date Mon, 05 Sep 2011 15:10:32 GMT
Author: thomasm
Date: Mon Sep  5 15:10:32 2011
New Revision: 1165315

URL: http://svn.apache.org/viewvc?rev=1165315&view=rev
Log:
Index mechanism (WIP) - move utility methods

Modified:
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/index/BTree.java
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/index/BTreeLeaf.java
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/index/IndexNode.java
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/util/StringUtils.java

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/index/BTree.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/index/BTree.java?rev=1165315&r1=1165314&r2=1165315&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/index/BTree.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/index/BTree.java
Mon Sep  5 15:10:32 2011
@@ -97,29 +97,6 @@ public class BTree {
         return indexer.getPage(this, parent, name);
     }
 
-    static String[] insert(String[] data, int pos, String d) {
-        String[] data2 = new String[data.length + 1];
-        if (pos > 0 && data.length > 0) {
-            System.arraycopy(data, 0, data2, 0, pos);
-        }
-        data2[pos] = d;
-        if (pos < data.length) {
-            System.arraycopy(data, pos, data2, pos + 1, data.length - pos);
-        }
-        return data2;
-    }
-
-    static String[] delete(String[] data, int pos) {
-        String[] data2 = new String[data.length - 1];
-        if (pos > 0 && data.length > 0) {
-            System.arraycopy(data, 0, data2, 0, pos);
-        }
-        if (pos < data.length) {
-            System.arraycopy(data, pos + 1, data2, pos, data.length - pos - 1);
-        }
-        return data2;
-    }
-
     public Cursor findFirst(String key) {
         Cursor c = new Cursor();
         BTreePage node = getPage(null, "");

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/index/BTreeLeaf.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/index/BTreeLeaf.java?rev=1165315&r1=1165314&r2=1165315&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/index/BTreeLeaf.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/index/BTreeLeaf.java
Mon Sep  5 15:10:32 2011
@@ -19,6 +19,7 @@ package org.apache.jackrabbit.mk.index;
 import java.util.Arrays;
 import org.apache.jackrabbit.mk.json.JsopBuilder;
 import org.apache.jackrabbit.mk.util.PathUtils;
+import org.apache.jackrabbit.mk.util.StringUtils;
 
 /**
  * An index leaf page.
@@ -49,13 +50,13 @@ class BTreeLeaf extends BTreePage {
     }
 
     void insert(int pos, String key, String value) {
-        keys = BTree.insert(keys, pos, key);
-        values = BTree.insert(values, pos, value);
+        keys = StringUtils.arrayInsert(keys, pos, key);
+        values = StringUtils.arrayInsert(values, pos, value);
     }
 
     void delete(int pos) {
-        keys = BTree.delete(keys, pos);
-        values = BTree.delete(values, pos);
+        keys = StringUtils.arrayRemove(keys, pos);
+        values = StringUtils.arrayRemove(values, pos);
     }
 
     void writeData() {

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/index/IndexNode.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/index/IndexNode.java?rev=1165315&r1=1165314&r2=1165315&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/index/IndexNode.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/index/IndexNode.java
Mon Sep  5 15:10:32 2011
@@ -19,6 +19,7 @@ package org.apache.jackrabbit.mk.index;
 import java.util.Arrays;
 import org.apache.jackrabbit.mk.json.JsopBuilder;
 import org.apache.jackrabbit.mk.util.PathUtils;
+import org.apache.jackrabbit.mk.util.StringUtils;
 
 /**
  * An index node page.
@@ -120,16 +121,16 @@ class IndexNode extends BTreePage {
     void delete(int pos) {
         if (size() > 0) {
             // empty parent
-            keys = BTree.delete(keys, Math.max(0, pos - 1));
-            values = BTree.delete(values, Math.max(0, pos - 1));
+            keys = StringUtils.arrayRemove(keys, Math.max(0, pos - 1));
+            values = StringUtils.arrayRemove(values, Math.max(0, pos - 1));
         }
-        children = BTree.delete(children, pos);
+        children = StringUtils.arrayRemove(children, pos);
     }
 
     void insert(int pos, String key, String value, String child) {
-        keys = BTree.insert(keys, pos, key);
-        values = BTree.insert(values, pos, value);
-        children = BTree.insert(children, pos + 1, child);
+        keys = StringUtils.arrayInsert(keys, pos, key);
+        values = StringUtils.arrayInsert(values, pos, value);
+        children = StringUtils.arrayInsert(children, pos + 1, child);
     }
 
 }
\ No newline at end of file

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/util/StringUtils.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/util/StringUtils.java?rev=1165315&r1=1165314&r2=1165315&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/util/StringUtils.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/util/StringUtils.java
Mon Sep  5 15:10:32 2011
@@ -80,4 +80,112 @@ public class StringUtils {
         }
     }
 
+    /**
+     * Insert an element into an array at the given position.
+     *
+     * @param values the values
+     * @param index the index
+     * @param x the value to add
+     * @return the new array
+     */
+    public static int[] arrayInsert(int[] values, int index, int x) {
+        int size = values.length;
+        int[] v2 = new int[size + 1];
+        v2[index] = x;
+        copyArrayAdd(values, v2, size, index);
+        return v2;
+    }
+
+    /**
+     * Insert an element into an array at the given position.
+     *
+     * @param values the values
+     * @param index the index
+     * @param x the value to add
+     * @return the new array
+     */
+    public static long[] arrayInsert(long[] values, int index, long x) {
+        int size = values.length;
+        long[] v2 = new long[size + 1];
+        v2[index] = x;
+        copyArrayAdd(values, v2, size, index);
+        return v2;
+    }
+
+    /**
+     * Insert an element into an array at the given position.
+     *
+     * @param values the values
+     * @param index the index
+     * @param x the value to add
+     * @return the new array
+     */
+    public static String[] arrayInsert(String[] values, int index, String x) {
+        int size = values.length;
+        String[] v2 = new String[size + 1];
+        v2[index] = x;
+        copyArrayAdd(values, v2, size, index);
+        return v2;
+    }
+
+    /**
+     * Remove an element from an array at the given position.
+     *
+     * @param values the values
+     * @param index the index
+     * @return the new array
+     */
+    public static int[] arrayRemove(int[] values, int index) {
+        int size = values.length;
+        int[] v2 = new int[size - 1];
+        copyArrayRemove(values, v2, size, index);
+        return v2;
+    }
+
+    /**
+     * Remove an element from an array at the given position.
+     *
+     * @param values the values
+     * @param index the index
+     * @return the new array
+     */
+    public static long[] arrayRemove(long[] values, int index) {
+        int size = values.length;
+        long[] v2 = new long[size - 1];
+        copyArrayRemove(values, v2, size, index);
+        return v2;
+    }
+
+    /**
+     * Remove an element from an array at the given position.
+     *
+     * @param values the values
+     * @param index the index
+     * @return the new array
+     */
+    public static String[] arrayRemove(String[] values, int index) {
+        int size = values.length;
+        String[] v2 = new String[size - 1];
+        copyArrayRemove(values, v2, size, index);
+        return v2;
+    }
+
+    private static void copyArrayAdd(Object src, Object dst, int size, int index) {
+        if (index > 0) {
+            System.arraycopy(src, 0, dst, 0, index);
+        }
+        if (index < size) {
+            System.arraycopy(src, index, dst, index + 1, size - index);
+        }
+    }
+
+    private static void copyArrayRemove(Object src, Object dst, int size, int index) {
+        if (index > 0 && size > 0) {
+            System.arraycopy(src, 0, dst, 0, index);
+        }
+        if (index < size) {
+            System.arraycopy(src, index + 1, dst, index, size - index - 1);
+        }
+    }
+
 }



Mime
View raw message