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 2009/10/15 17:42:15 UTC

svn commit: r825527 - in /lucene/lucy/trunk/core/Lucy/Index: Snapshot.bp Snapshot.c

Author: marvin
Date: Thu Oct 15 15:42:14 2009
New Revision: 825527

URL: http://svn.apache.org/viewvc?rev=825527&view=rev
Log:
Commit LUCY-50, adding Snapshot.

Added:
    lucene/lucy/trunk/core/Lucy/Index/Snapshot.bp   (with props)
    lucene/lucy/trunk/core/Lucy/Index/Snapshot.c   (with props)

Added: lucene/lucy/trunk/core/Lucy/Index/Snapshot.bp
URL: http://svn.apache.org/viewvc/lucene/lucy/trunk/core/Lucy/Index/Snapshot.bp?rev=825527&view=auto
==============================================================================
--- lucene/lucy/trunk/core/Lucy/Index/Snapshot.bp (added)
+++ lucene/lucy/trunk/core/Lucy/Index/Snapshot.bp Thu Oct 15 15:42:14 2009
@@ -0,0 +1,79 @@
+parcel Lucy;
+
+/** Point-in-time index file list.
+ *
+ * A Snapshot is list of index files.  Because index files, once written, are
+ * never modified, the list of files in a Snapshot defines a point-in-time
+ * view of the data in an index.
+ *
+ * IndexReader objects interpret the data associated with a single Snapshot.
+ */
+
+class Lucy::Index::Snapshot extends Lucy::Object::Obj : dumpable {
+
+    Hash        *entries;
+    CharBuf     *filename;
+
+    inert i32_t current_file_format;
+
+    public inert incremented Snapshot* 
+    new();
+    
+    /**
+     * Constructor.  Takes no arguments.
+     */
+    public inert Snapshot* 
+    init(Snapshot *self);
+
+    /** Return a list of all entries.
+     */
+    public incremented VArray*
+    List(Snapshot *self);
+
+    /** Return the number of entries (including directories).
+     */
+    public u32_t
+    Num_Entries(Snapshot *self);
+
+
+    /** Add a filepath to the snapshot. 
+     */
+    public void
+    Add_Entry(Snapshot *self, const CharBuf *entry);
+
+    /** Delete a filepath from the snapshot.
+     *
+     * @return true if the entry existed and was successfully deleted, false
+     * otherwise.
+     */
+    public bool_t
+    Delete_Entry(Snapshot *self, const CharBuf *entry);
+
+    void
+    Set_Filename(Snapshot *self, const CharBuf *filename);
+
+    /** The name of the file that the Snapshot serves as a proxy for.
+     * Initially NULL; updated by Read_File() and Write_File().
+     */
+    public CharBuf*
+    Get_Filename(Snapshot *self);
+
+    public void 
+    Destroy(Snapshot *self);
+}
+
+/* Copyright 2009 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+

Propchange: lucene/lucy/trunk/core/Lucy/Index/Snapshot.bp
------------------------------------------------------------------------------
    svn:eol-style = native

Added: lucene/lucy/trunk/core/Lucy/Index/Snapshot.c
URL: http://svn.apache.org/viewvc/lucene/lucy/trunk/core/Lucy/Index/Snapshot.c?rev=825527&view=auto
==============================================================================
--- lucene/lucy/trunk/core/Lucy/Index/Snapshot.c (added)
+++ lucene/lucy/trunk/core/Lucy/Index/Snapshot.c Thu Oct 15 15:42:14 2009
@@ -0,0 +1,91 @@
+#define C_LUCY_SNAPSHOT
+#include "Lucy/Util/ToolSet.h"
+
+#include "Lucy/Index/Snapshot.h"
+#include "Lucy/Util/StringHelper.h"
+
+i32_t Snapshot_current_file_format = 1;
+
+Snapshot*
+Snapshot_new()
+{
+    Snapshot *self = (Snapshot*)VTable_Make_Obj(SNAPSHOT);
+    return Snapshot_init(self);
+}
+
+static void
+S_zero_out(Snapshot *self)
+{
+    DECREF(self->entries);
+    DECREF(self->filename);
+    self->entries  = Hash_new(0);
+    self->filename = NULL;
+}
+
+Snapshot*
+Snapshot_init(Snapshot *self)
+{
+    S_zero_out(self);
+    return self;
+}
+
+void
+Snapshot_destroy(Snapshot *self)
+{
+    DECREF(self->entries);
+    DECREF(self->filename);
+    SUPER_DESTROY(self, SNAPSHOT);
+}
+
+void
+Snapshot_add_entry(Snapshot *self, const CharBuf *filename)
+{
+    Hash_Store(self->entries, (Obj*)filename, INCREF(&EMPTY));
+}
+
+bool_t
+Snapshot_delete_entry(Snapshot *self, const CharBuf *entry)
+{
+    Obj *val = Hash_Delete(self->entries, (Obj*)entry);
+    if (val) { 
+        Obj_Dec_RefCount(val);
+        return true;
+    }
+    else {
+        return false;
+    }
+}
+
+VArray*
+Snapshot_list(Snapshot *self) { 
+    return Hash_Keys(self->entries); 
+}
+
+u32_t
+Snapshot_num_entries(Snapshot *self) { return Hash_Get_Size(self->entries); }
+
+void
+Snapshot_set_filename(Snapshot *self, const CharBuf *filename)
+{
+    DECREF(self->filename);
+    self->filename = filename ? CB_Clone(filename) : NULL;
+}
+
+CharBuf*
+Snapshot_get_filename(Snapshot *self) { return self->filename; }
+
+/* Copyright 2009 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+

Propchange: lucene/lucy/trunk/core/Lucy/Index/Snapshot.c
------------------------------------------------------------------------------
    svn:eol-style = native