Repository: ignite
Updated Branches:
  refs/heads/ignite-1770 6768e9d5e -> 37269c1f5


IGNITE-1770: WIP on schema hashing.


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

Branch: refs/heads/ignite-1770
Commit: 08238902013e1fa2742d8c5fea12dff2190d7419
Parents: 6768e9d
Author: vozerov-gridgain <[email protected]>
Authored: Wed Oct 28 13:42:14 2015 +0300
Committer: vozerov-gridgain <[email protected]>
Committed: Wed Oct 28 13:42:14 2015 +0300

----------------------------------------------------------------------
 .../internal/portable/PortableWriterExImpl.java | 24 ++++++++++++++++++++
 1 file changed, 24 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/08238902/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableWriterExImpl.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableWriterExImpl.java
 
b/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableWriterExImpl.java
index 382b2f9..fc6d6c1 100644
--- 
a/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableWriterExImpl.java
+++ 
b/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableWriterExImpl.java
@@ -93,6 +93,12 @@ public class PortableWriterExImpl implements PortableWriter, 
PortableRawWriterEx
     /** */
     private static final int INIT_CAP = 1024;
 
+    /** FNV1 hash offset basis. */
+    private static final int FNV1_OFFSET_BASIS = 0x811C9DC5;
+
+    /** FNV1 hash prime. */
+    private static final int FNV1_PRIME = 0x01000193;
+
     /** Thread-local schema. */
     private static final ThreadLocal<SchemaHolder> SCHEMA = new 
ThreadLocal<>();
 
@@ -126,6 +132,9 @@ public class PortableWriterExImpl implements 
PortableWriter, PortableRawWriterEx
     /** Schema. */
     private SchemaHolder schema;
 
+    /** Schema ID. */
+    private int schemaId;
+
     /** Amount of written fields. */
     private int fieldCnt;
 
@@ -1713,8 +1722,23 @@ public class PortableWriterExImpl implements 
PortableWriter, PortableRawWriterEx
 
                 SCHEMA.set(schema);
             }
+
+            // Initialize offset when the first field is written.
+            schemaId = FNV1_OFFSET_BASIS;
         }
 
+        // Advance schema hash.
+        int schemaId0 = schemaId ^ (fieldId & 0xFF);
+        schemaId0 = schemaId0 * FNV1_PRIME;
+        schemaId0 = schemaId0 ^ ((fieldId >> 8) & 0xFF);
+        schemaId0 = schemaId0 * FNV1_PRIME;
+        schemaId0 = schemaId0 ^ ((fieldId >> 16) & 0xFF);
+        schemaId0 = schemaId0 * FNV1_PRIME;
+        schemaId0 = schemaId0 ^ ((fieldId >> 24) & 0xFF);
+        schemaId0 = schemaId0 * FNV1_PRIME;
+
+        schemaId = schemaId0;
+
         schema.push(fieldId, fieldOff);
 
         fieldCnt++;

Reply via email to