You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucy.apache.org by ma...@apache.org on 2010/06/08 05:09:08 UTC

svn commit: r952517 - in /lucene/lucy/trunk/core/Lucy: Object/ByteBuf.bp Object/ByteBuf.c Object/CharBuf.bp Object/CharBuf.c Object/Num.bp Object/Num.c Object/Obj.bp Test/Object/TestByteBuf.c Test/Object/TestCharBuf.c Test/Object/TestNum.c

Author: marvin
Date: Tue Jun  8 03:09:08 2010
New Revision: 952517

URL: http://svn.apache.org/viewvc?rev=952517&view=rev
Log:
Add Scalar_ID() method to core scalar objects, allowing for fast switch-based
polymorphism by type.

Modified:
    lucene/lucy/trunk/core/Lucy/Object/ByteBuf.bp
    lucene/lucy/trunk/core/Lucy/Object/ByteBuf.c
    lucene/lucy/trunk/core/Lucy/Object/CharBuf.bp
    lucene/lucy/trunk/core/Lucy/Object/CharBuf.c
    lucene/lucy/trunk/core/Lucy/Object/Num.bp
    lucene/lucy/trunk/core/Lucy/Object/Num.c
    lucene/lucy/trunk/core/Lucy/Object/Obj.bp
    lucene/lucy/trunk/core/Lucy/Test/Object/TestByteBuf.c
    lucene/lucy/trunk/core/Lucy/Test/Object/TestCharBuf.c
    lucene/lucy/trunk/core/Lucy/Test/Object/TestNum.c

Modified: lucene/lucy/trunk/core/Lucy/Object/ByteBuf.bp
URL: http://svn.apache.org/viewvc/lucene/lucy/trunk/core/Lucy/Object/ByteBuf.bp?rev=952517&r1=952516&r2=952517&view=diff
==============================================================================
--- lucene/lucy/trunk/core/Lucy/Object/ByteBuf.bp (original)
+++ lucene/lucy/trunk/core/Lucy/Object/ByteBuf.bp Tue Jun  8 03:09:08 2010
@@ -109,6 +109,9 @@ class Lucy::Object::ByteBuf cnick BB ext
 
     public incremented ByteBuf*
     Deserialize(ByteBuf *self, InStream *instream);
+
+    uint8_t
+    Scalar_ID(ByteBuf *self);
 }
 
 /**

Modified: lucene/lucy/trunk/core/Lucy/Object/ByteBuf.c
URL: http://svn.apache.org/viewvc/lucene/lucy/trunk/core/Lucy/Object/ByteBuf.c?rev=952517&r1=952516&r2=952517&view=diff
==============================================================================
--- lucene/lucy/trunk/core/Lucy/Object/ByteBuf.c (original)
+++ lucene/lucy/trunk/core/Lucy/Object/ByteBuf.c Tue Jun  8 03:09:08 2010
@@ -234,6 +234,13 @@ BB_compare_to(ByteBuf *self, Obj *other)
     return BB_compare(&self, &other);
 }
 
+uint8_t
+BB_scalar_id(ByteBuf *self)
+{
+    UNUSED_VAR(self);
+    return Obj_BLOB;
+}
+
 /******************************************************************/
 
 ViewByteBuf*

Modified: lucene/lucy/trunk/core/Lucy/Object/CharBuf.bp
URL: http://svn.apache.org/viewvc/lucene/lucy/trunk/core/Lucy/Object/CharBuf.bp?rev=952517&r1=952516&r2=952517&view=diff
==============================================================================
--- lucene/lucy/trunk/core/Lucy/Object/CharBuf.bp (original)
+++ lucene/lucy/trunk/core/Lucy/Object/CharBuf.bp Tue Jun  8 03:09:08 2010
@@ -220,6 +220,9 @@ class Lucy::Object::CharBuf cnick CB
     public incremented CharBuf*
     Deserialize(CharBuf *self, InStream *instream);
 
+    uint8_t
+    Scalar_ID(CharBuf *self);
+
     /** Remove Unicode whitespace characters from both top and tail.
      */
     uint32_t

Modified: lucene/lucy/trunk/core/Lucy/Object/CharBuf.c
URL: http://svn.apache.org/viewvc/lucene/lucy/trunk/core/Lucy/Object/CharBuf.c?rev=952517&r1=952516&r2=952517&view=diff
==============================================================================
--- lucene/lucy/trunk/core/Lucy/Object/CharBuf.c (original)
+++ lucene/lucy/trunk/core/Lucy/Object/CharBuf.c Tue Jun  8 03:09:08 2010
@@ -475,6 +475,13 @@ CB_deserialize(CharBuf *self, InStream *
     return self;
 }
 
+uint8_t
+CB_scalar_id(CharBuf *self)
+{
+    UNUSED_VAR(self);
+    return Obj_TEXT;
+}
+
 void
 CB_mimic_str(CharBuf *self, const char* ptr, size_t size) 
 {

Modified: lucene/lucy/trunk/core/Lucy/Object/Num.bp
URL: http://svn.apache.org/viewvc/lucene/lucy/trunk/core/Lucy/Object/Num.bp?rev=952517&r1=952516&r2=952517&view=diff
==============================================================================
--- lucene/lucy/trunk/core/Lucy/Object/Num.bp (original)
+++ lucene/lucy/trunk/core/Lucy/Object/Num.bp Tue Jun  8 03:09:08 2010
@@ -79,6 +79,9 @@ class Lucy::Object::Float32 extends Lucy
 
     public void
     Mimic(Float32 *self, Obj *other);
+
+    uint8_t
+    Scalar_ID(Float32 *self);
 }
 
 /** Double precision floating point number.
@@ -122,6 +125,9 @@ class Lucy::Object::Float64 extends Lucy
 
     public void
     Mimic(Float64 *self, Obj *other);
+
+    uint8_t
+    Scalar_ID(Float64 *self);
 }
 
 /** 32-bit signed integer.
@@ -166,6 +172,9 @@ class Lucy::Object::Integer32 cnick Int3
 
     public void
     Mimic(Integer32 *self, Obj *other);
+
+    uint8_t
+    Scalar_ID(Integer32 *self);
 }
 
 /**
@@ -214,6 +223,9 @@ class Lucy::Object::Integer64 cnick Int6
 
     public void
     Mimic(Integer64 *self, Obj *other);
+
+    uint8_t
+    Scalar_ID(Integer64 *self);
 }
 
 /* Copyright 2009 The Apache Software Foundation

Modified: lucene/lucy/trunk/core/Lucy/Object/Num.c
URL: http://svn.apache.org/viewvc/lucene/lucy/trunk/core/Lucy/Object/Num.c?rev=952517&r1=952516&r2=952517&view=diff
==============================================================================
--- lucene/lucy/trunk/core/Lucy/Object/Num.c (original)
+++ lucene/lucy/trunk/core/Lucy/Object/Num.c Tue Jun  8 03:09:08 2010
@@ -147,6 +147,13 @@ Float32_deserialize(Float32 *self, InStr
     return self ? Float32_init(self, value) : Float32_new(value);
 }
 
+uint8_t
+Float32_scalar_id(Float32 *self)
+{
+    UNUSED_VAR(self);
+    return Obj_FLOAT32;
+}
+
 /***************************************************************************/
 
 Float64*
@@ -213,6 +220,13 @@ Float64_deserialize(Float64 *self, InStr
     return self ? Float64_init(self, value) : Float64_new(value);
 }
 
+uint8_t
+Float64_scalar_id(Float64 *self)
+{
+    UNUSED_VAR(self);
+    return Obj_FLOAT64;
+}
+
 /***************************************************************************/
 
 Integer32*
@@ -278,6 +292,13 @@ Int32_deserialize(Integer32 *self, InStr
     return self ? Int32_init(self, value) : Int32_new(value);
 }
 
+uint8_t
+Int32_scalar_id(Integer32 *self)
+{
+    UNUSED_VAR(self);
+    return Obj_INT32;
+}
+
 /***************************************************************************/
 
 Integer64*
@@ -362,6 +383,13 @@ Int64_deserialize(Integer64 *self, InStr
     return self ? Int64_init(self, value) : Int64_new(value);
 }
 
+uint8_t
+Int64_scalar_id(Integer64 *self)
+{
+    UNUSED_VAR(self);
+    return Obj_INT64;
+}
+
 /* Copyright 2009 The Apache Software Foundation
  *
  * Licensed under the Apache License, Version 2.0 (the "License");

Modified: lucene/lucy/trunk/core/Lucy/Object/Obj.bp
URL: http://svn.apache.org/viewvc/lucene/lucy/trunk/core/Lucy/Object/Obj.bp?rev=952517&r1=952516&r2=952517&view=diff
==============================================================================
--- lucene/lucy/trunk/core/Lucy/Object/Obj.bp (original)
+++ lucene/lucy/trunk/core/Lucy/Object/Obj.bp Tue Jun  8 03:09:08 2010
@@ -167,9 +167,45 @@ class Lucy::Object::Obj {
      */
     public abstract void
     Mimic(Obj *self, Obj *other);
+
+    /** Internal id used for switch() ops.  Unique for each scalar data type.
+     */
+    abstract uint8_t
+    Scalar_ID(Obj *self);
 }
 
 __C__
+
+#define lucy_Obj_TEXT    0x01
+#define lucy_Obj_BLOB    0x02
+#define lucy_Obj_INT8    0x03
+#define lucy_Obj_INT16   0x04
+#define lucy_Obj_INT32   0x05
+#define lucy_Obj_INT64   0x06
+#define lucy_Obj_UINT8   0x07
+#define lucy_Obj_UINT16  0x08
+#define lucy_Obj_UINT32  0x09
+#define lucy_Obj_UINT64  0x0a
+#define lucy_Obj_FLOAT32 0x0b
+#define lucy_Obj_FLOAT64 0x0c
+#define lucy_Obj_SCALAR_ID_MASK 0x0f
+
+#ifdef LUCY_USE_SHORT_NAMES
+  #define Obj_TEXT              lucy_Obj_TEXT
+  #define Obj_BLOB              lucy_Obj_BLOB
+  #define Obj_INT8              lucy_Obj_INT8
+  #define Obj_INT16             lucy_Obj_INT16
+  #define Obj_INT32             lucy_Obj_INT32
+  #define Obj_INT64             lucy_Obj_INT64
+  #define Obj_UINT8             lucy_Obj_UINT8
+  #define Obj_UINT16            lucy_Obj_UINT16
+  #define Obj_UINT32            lucy_Obj_UINT32
+  #define Obj_UINT64            lucy_Obj_UINT64
+  #define Obj_FLOAT32           lucy_Obj_FLOAT32
+  #define Obj_FLOAT64           lucy_Obj_FLOAT64
+  #define Obj_SCALAR_ID_MASK    lucy_Obj_SCALAR_ID_MASK
+#endif
+
 static CHY_INLINE void
 lucy_Obj_super_destroy(lucy_Obj *self, lucy_VTable *vtable)
 {

Modified: lucene/lucy/trunk/core/Lucy/Test/Object/TestByteBuf.c
URL: http://svn.apache.org/viewvc/lucene/lucy/trunk/core/Lucy/Test/Object/TestByteBuf.c?rev=952517&r1=952516&r2=952517&view=diff
==============================================================================
--- lucene/lucy/trunk/core/Lucy/Test/Object/TestByteBuf.c (original)
+++ lucene/lucy/trunk/core/Lucy/Test/Object/TestByteBuf.c Tue Jun  8 03:09:08 2010
@@ -122,6 +122,14 @@ test_Cat(TestBatch *batch)
 }
 
 static void
+test_Scalar_ID(TestBatch *batch)
+{
+    ByteBuf *bytebuf = BB_new_bytes("foo", 3);
+    ASSERT_INT_EQ(batch, BB_Scalar_ID(bytebuf), Obj_BLOB, "Scalar_ID");
+    DECREF(bytebuf);
+}
+
+static void
 test_serialization(TestBatch *batch)
 {
     ByteBuf *wanted = BB_new_bytes("foobar", 6);
@@ -135,7 +143,7 @@ test_serialization(TestBatch *batch)
 void
 TestBB_run_tests()
 {
-    TestBatch *batch = TestBatch_new(22);
+    TestBatch *batch = TestBatch_new(23);
     TestBatch_Plan(batch);
 
     test_Equals(batch);
@@ -144,6 +152,7 @@ TestBB_run_tests()
     test_compare(batch);
     test_Mimic(batch);
     test_Cat(batch);
+    test_Scalar_ID(batch);
     test_serialization(batch);
 
     DECREF(batch);

Modified: lucene/lucy/trunk/core/Lucy/Test/Object/TestCharBuf.c
URL: http://svn.apache.org/viewvc/lucene/lucy/trunk/core/Lucy/Test/Object/TestCharBuf.c?rev=952517&r1=952516&r2=952517&view=diff
==============================================================================
--- lucene/lucy/trunk/core/Lucy/Test/Object/TestCharBuf.c (original)
+++ lucene/lucy/trunk/core/Lucy/Test/Object/TestCharBuf.c Tue Jun  8 03:09:08 2010
@@ -365,6 +365,14 @@ test_vcatf_x32(TestBatch *batch)
 }
 
 static void
+test_Scalar_ID(TestBatch *batch)
+{
+    CharBuf *charbuf = S_get_cb("foo");
+    ASSERT_INT_EQ(batch, CB_Scalar_ID(charbuf), Obj_TEXT, "Scalar_ID");
+    DECREF(charbuf);
+}
+
+static void
 test_serialization(TestBatch *batch)
 {
     CharBuf *wanted = S_get_cb("foo");
@@ -378,7 +386,7 @@ test_serialization(TestBatch *batch)
 void
 TestCB_run_tests()
 {
-    TestBatch *batch = TestBatch_new(49);
+    TestBatch *batch = TestBatch_new(50);
     TestBatch_Plan(batch);
 
     test_vcatf_s(batch);
@@ -403,6 +411,7 @@ TestCB_run_tests()
     test_Trim(batch);
     test_To_F64(batch);
     test_To_I64(batch);
+    test_Scalar_ID(batch);
     test_serialization(batch);
 
     DECREF(batch);

Modified: lucene/lucy/trunk/core/Lucy/Test/Object/TestNum.c
URL: http://svn.apache.org/viewvc/lucene/lucy/trunk/core/Lucy/Test/Object/TestNum.c?rev=952517&r1=952516&r2=952517&view=diff
==============================================================================
--- lucene/lucy/trunk/core/Lucy/Test/Object/TestNum.c (original)
+++ lucene/lucy/trunk/core/Lucy/Test/Object/TestNum.c Tue Jun  8 03:09:08 2010
@@ -232,10 +232,33 @@ test_serialization(TestBatch *batch)
     DECREF(f32);
 }
 
+static void
+test_Scalar_ID(TestBatch *batch)
+{
+    Float32   *f32 = Float32_new(0);
+    Float64   *f64 = Float64_new(0);
+    Integer32 *i32 = Int32_new(0);
+    Integer64 *i64 = Int64_new(0);
+
+    ASSERT_INT_EQ(batch, Float32_Scalar_ID(f32), Obj_FLOAT32,
+        "Float32_Scalar_ID");
+    ASSERT_INT_EQ(batch, Float64_Scalar_ID(f64), Obj_FLOAT64,
+        "Float64_Scalar_ID");
+    ASSERT_INT_EQ(batch, Int32_Scalar_ID(i32), Obj_INT32,
+        "Int32_Scalar_ID");
+    ASSERT_INT_EQ(batch, Int64_Scalar_ID(i64), Obj_INT64,
+        "Int64_Scalar_ID");
+
+    DECREF(i64);
+    DECREF(i32);
+    DECREF(f64);
+    DECREF(f32);
+}
+
 void
 TestNum_run_tests()
 {
-    TestBatch *batch = TestBatch_new(42);
+    TestBatch *batch = TestBatch_new(46);
     TestBatch_Plan(batch);
 
     test_To_String(batch);
@@ -244,6 +267,7 @@ TestNum_run_tests()
     test_Clone(batch);
     test_Mimic(batch);
     test_serialization(batch);
+    test_Scalar_ID(batch);
     
     DECREF(batch);
 }