You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mnemonic.apache.org by ga...@apache.org on 2016/04/05 00:53:33 UTC

[3/4] incubator-mnemonic git commit: add native param conversion as well as test the webhook of Appache mirrored repo in Github

add native param conversion as well as test the webhook of Appache mirrored repo in Github


Project: http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/commit/cfc9a73f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/tree/cfc9a73f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/diff/cfc9a73f

Branch: refs/heads/master
Commit: cfc9a73f7773d16ce5a68e8f169c32da8f006ffb
Parents: 5918930
Author: Wang, Gang(Gary) <ga...@intel.com>
Authored: Fri Apr 1 21:47:12 2016 -0700
Committer: Wang, Gang(Gary) <ga...@intel.com>
Committed: Fri Apr 1 21:47:12 2016 -0700

----------------------------------------------------------------------
 .../main/java/com/intel/bigdatamem/Utils.java   | 79 ++++++++++++++++++++
 1 file changed, 79 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/cfc9a73f/core/src/main/java/com/intel/bigdatamem/Utils.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/com/intel/bigdatamem/Utils.java b/core/src/main/java/com/intel/bigdatamem/Utils.java
index cc7bbf0..14a895a 100644
--- a/core/src/main/java/com/intel/bigdatamem/Utils.java
+++ b/core/src/main/java/com/intel/bigdatamem/Utils.java
@@ -302,4 +302,83 @@ public class Utils {
         return "{" + String.join(",", slist) + "}";
     }
 
+    /**
+     * retrieve a set of native field info from a list of object field info according to the field
+     * id info. it forms a value info stack for native code to use as one standardized parameter
+     *
+     * @param objstack
+     *           a stack of object info retrieved from Durable.getNativeFieldInfo(), order matters
+     *
+     * @param fidinfostack
+     *           a stack of field id in the form of (next_fid, next_level_fid) order follows objstack
+     *           the last next_level_fid specifies the value's fid.
+     *           the last item of next_fid could be null if there is no next node
+     *           if it is null that means the last item is a object instead of node
+     *
+     * @return   the stack of native field info
+     *
+     */
+    public static List<long[]> getNativeParamForm(List<long[][]> objstack, long[][] fidinfostack) {
+        List<long[]> ret = new ArrayList<long[]>();
+        if (null == objstack ||
+            null == fidinfostack ||
+            fidinfostack.length != objstack.size()) {
+            throw new IllegalArgumentException("Not the same depth");
+        }
+        for (int idx = 0; idx < fidinfostack.length; ++idx) {
+            ret.add(genNativeStackItem(objstack.get(idx), fidinfostack[idx],
+                    idx == fidinfostack.length - 1));
+        }
+        return ret;
+    }
+
+    /**
+     * generate an item of native stack.
+     *
+     * @param oinfo
+     *           a object field info
+     *
+     * @param fidinfo
+     *           a pair of field id info
+     *
+     * @param allowfidnull
+     *           allow the first field id is null
+     *
+     * @return the native item
+     */
+    public static long[] genNativeStackItem(long[][] oinfo, long[] fidinfo, boolean allowfidnull) {
+        long[] ret = new long[4];
+        long fid;
+        boolean found;
+        if (fidinfo.length != 2) {
+            throw new IllegalArgumentException("the length of field id array is not exactly 2");
+        }
+        for (int idx = 0; idx < fidinfo.length; ++idx) {
+            ret[idx*2] = 0;
+            ret[idx*2 + 1] = 0;
+            fid = fidinfo[idx];
+            if (fid <= 0) {
+                if (allowfidnull && 0 == idx) {
+                    continue;
+                } else {
+                    throw new IllegalArgumentException("the field id is not greater than 0");
+                }
+            }
+            found = false;
+            for (long[] finfo : oinfo) {
+                if (finfo.length != 3) {
+                    throw new IllegalArgumentException("the length of field array is not exactly 3");
+                }
+                if (fid == finfo[0]) {
+                    ret[idx*2] = finfo[1];
+                    ret[idx*2 + 1] = finfo[2];
+                    found = true;
+                }
+            }
+            if (!found) {
+                throw new IllegalArgumentException("field id not found");
+            }
+        }
+        return ret;
+    }
 }