FAQ

svn commit: r883826 - in /lucene/lucy/trunk: core/Lucy/Store/ core/Lucy/Test/Store/ perl/lib/Lucy/ perl/t/core/

Marvin
Nov 24, 2009 at 7:25 pm
Author: marvin
Date: Tue Nov 24 19:24:46 2009
New Revision: 883826

URL: http://svn.apache.org/viewvc?rev=883826&view=rev
Log:
Commit LUCY-73, adding RAMDirHandle and enabling RAMFolder_Open_Dir().

Added:
lucene/lucy/trunk/core/Lucy/Store/RAMDirHandle.bp (with props)
lucene/lucy/trunk/core/Lucy/Store/RAMDirHandle.c (with props)
lucene/lucy/trunk/core/Lucy/Test/Store/TestRAMDirHandle.bp (with props)
lucene/lucy/trunk/core/Lucy/Test/Store/TestRAMDirHandle.c (with props)
lucene/lucy/trunk/perl/t/core/061-ram_dir_handle.t (with props)
Modified:
lucene/lucy/trunk/core/Lucy/Store/RAMFolder.bp
lucene/lucy/trunk/core/Lucy/Store/RAMFolder.c
lucene/lucy/trunk/core/Lucy/Test/Store/TestRAMFolder.c
lucene/lucy/trunk/perl/lib/Lucy/Test.pm

Added: lucene/lucy/trunk/core/Lucy/Store/RAMDirHandle.bp
URL: http://svn.apache.org/viewvc/lucene/lucy/trunk/core/Lucy/Store/RAMDirHandle.bp?rev=883826&view=auto
==============================================================================
--- lucene/lucy/trunk/core/Lucy/Store/RAMDirHandle.bp (added)
+++ lucene/lucy/trunk/core/Lucy/Store/RAMDirHandle.bp Tue Nov 24 19:24:46 2009
@@ -0,0 +1,42 @@
+parcel Lucy;
+
+/** DirHandle for RAMFolder.
+ */
+class Lucy::Store::RAMDirHandle cnick RAMDH
+ extends Lucy::Store::DirHandle {
+
+ RAMFolder *folder;
+ VArray *elems;
+ i32_t tick;
+
+ inert incremented RAMDirHandle*
+ new(RAMFolder *folder);
+
+ inert RAMDirHandle*
+ init(RAMDirHandle *self, RAMFolder *folder);
+
+ bool_t
+ Next(RAMDirHandle *self);
+
+ bool_t
+ Entry_Is_Dir(RAMDirHandle *self);
+
+ bool_t
+ Close(RAMDirHandle *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/Store/RAMDirHandle.bp
------------------------------------------------------------------------------
svn:eol-style = native

Added: lucene/lucy/trunk/core/Lucy/Store/RAMDirHandle.c
URL: http://svn.apache.org/viewvc/lucene/lucy/trunk/core/Lucy/Store/RAMDirHandle.c?rev=883826&view=auto
==============================================================================
--- lucene/lucy/trunk/core/Lucy/Store/RAMDirHandle.c (added)
+++ lucene/lucy/trunk/core/Lucy/Store/RAMDirHandle.c Tue Nov 24 19:24:46 2009
@@ -0,0 +1,85 @@
+#define C_LUCY_RAMFOLDER
+#define C_LUCY_RAMDIRHANDLE
+#include "Lucy/Util/ToolSet.h"
+
+#include "Lucy/Store/RAMDirHandle.h"
+#include "Lucy/Store/RAMFolder.h"
+#include "Lucy/Util/IndexFileNames.h"
+
+RAMDirHandle*
+RAMDH_new(RAMFolder *folder)
+{
+ RAMDirHandle *self = (RAMDirHandle*)VTable_Make_Obj(RAMDIRHANDLE);
+ return RAMDH_init(self, folder);
+}
+
+RAMDirHandle*
+RAMDH_init(RAMDirHandle *self, RAMFolder *folder)
+{
+ DH_init((DirHandle*)self, RAMFolder_Get_Path(folder));
+ self->folder = (RAMFolder*)INCREF(folder);
+ self->elems = Hash_Keys(self->folder->entries);
+ self->tick = -1;
+ return self;
+}
+
+bool_t
+RAMDH_close(RAMDirHandle *self)
+{
+ if (self->elems) {
+ Obj_Dec_RefCount(self->elems);
+ self->elems = NULL;
+ }
+ if (self->folder) {
+ Obj_Dec_RefCount(self->folder);
+ self->folder = NULL;
+ }
+ return true;
+}
+
+bool_t
+RAMDH_next(RAMDirHandle *self)
+{
+ if (self->elems) {
+ self->tick++;
+ if (self->tick < (i32_t)VA_Get_Size(self->elems)) {
+ CharBuf *path = (CharBuf*)CERTIFY(
+ VA_Fetch(self->elems, self->tick), CHARBUF);
+ CB_Mimic(self->entry, (Obj*)path);
+ return true;
+ }
+ else {
+ self->tick--;
+ return false;
+ }
+ }
+ return false;
+}
+
+bool_t
+RAMDH_entry_is_dir(RAMDirHandle *self)
+{
+ if (self->elems) {
+ CharBuf *name = (CharBuf*)VA_Fetch(self->elems, self->tick);
+ if (name) {
+ return Folder_Local_Is_Directory(self->folder, name);
+ }
+ }
+ return false;
+}
+
+/* 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/Store/RAMDirHandle.c
------------------------------------------------------------------------------
svn:eol-style = native

Modified: lucene/lucy/trunk/core/Lucy/Store/RAMFolder.bp
URL: http://svn.apache.org/viewvc/lucene/lucy/trunk/core/Lucy/Store/RAMFolder.bp?rev=883826&r1=883825&r2=883826&view=diff
==============================================================================
--- lucene/lucy/trunk/core/Lucy/Store/RAMFolder.bp (original)
+++ lucene/lucy/trunk/core/Lucy/Store/RAMFolder.bp Tue Nov 24 19:24:46 2009
@@ -29,6 +29,9 @@
incremented FileHandle*
Local_Open_FileHandle(RAMFolder *self, const CharBuf *name, u32_t flags);

+ incremented DirHandle*
+ Local_Open_Dir(RAMFolder *self);
+
bool_t
Local_MkDir(RAMFolder *self, const CharBuf *name);


Modified: lucene/lucy/trunk/core/Lucy/Store/RAMFolder.c
URL: http://svn.apache.org/viewvc/lucene/lucy/trunk/core/Lucy/Store/RAMFolder.c?rev=883826&r1=883825&r2=883826&view=diff
==============================================================================
--- lucene/lucy/trunk/core/Lucy/Store/RAMFolder.c (original)
+++ lucene/lucy/trunk/core/Lucy/Store/RAMFolder.c Tue Nov 24 19:24:46 2009
@@ -4,6 +4,7 @@
#include "Lucy/Store/RAMFolder.h"
#include "Lucy/Store/InStream.h"
#include "Lucy/Store/OutStream.h"
+#include "Lucy/Store/RAMDirHandle.h"
#include "Lucy/Store/RAMFile.h"
#include "Lucy/Store/RAMFileHandle.h"
#include "Lucy/Util/IndexFileNames.h"
@@ -100,6 +101,14 @@
return (FileHandle*)fh;
}

+DirHandle*
+RAMFolder_local_open_dir(RAMFolder *self)
+{
+ RAMDirHandle *dh = RAMDH_new(self);
+ if (!dh) { ERR_ADD_FRAME(Err_get_error()); }
+ return (DirHandle*)dh;
+}
+
bool_t
RAMFolder_local_exists(RAMFolder *self, const CharBuf *name)
{

Added: lucene/lucy/trunk/core/Lucy/Test/Store/TestRAMDirHandle.bp
URL: http://svn.apache.org/viewvc/lucene/lucy/trunk/core/Lucy/Test/Store/TestRAMDirHandle.bp?rev=883826&view=auto
==============================================================================
--- lucene/lucy/trunk/core/Lucy/Test/Store/TestRAMDirHandle.bp (added)
+++ lucene/lucy/trunk/core/Lucy/Test/Store/TestRAMDirHandle.bp Tue Nov 24 19:24:46 2009
@@ -0,0 +1,22 @@
+parcel Lucy;
+
+inert class Lucy::Test::Store::TestRAMDirHandle cnick TestRAMDH {
+ inert void
+ run_tests();
+}
+
+/* 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/Test/Store/TestRAMDirHandle.bp
------------------------------------------------------------------------------
svn:eol-style = native

Added: lucene/lucy/trunk/core/Lucy/Test/Store/TestRAMDirHandle.c
URL: http://svn.apache.org/viewvc/lucene/lucy/trunk/core/Lucy/Test/Store/TestRAMDirHandle.c?rev=883826&view=auto
==============================================================================
--- lucene/lucy/trunk/core/Lucy/Test/Store/TestRAMDirHandle.c (added)
+++ lucene/lucy/trunk/core/Lucy/Test/Store/TestRAMDirHandle.c Tue Nov 24 19:24:46 2009
@@ -0,0 +1,94 @@
+#define C_LUCY_RAMFOLDER
+#define C_LUCY_CHARBUF
+#include "Lucy/Util/ToolSet.h"
+
+#define CHAZ_USE_SHORT_NAMES
+#include "Charmonizer/Test.h"
+
+#include "Lucy/Test/Store/TestRAMDirHandle.h"
+#include "Lucy/Store/FileHandle.h"
+#include "Lucy/Store/RAMFolder.h"
+#include "Lucy/Store/RAMDirHandle.h"
+
+static CharBuf foo = ZCB_LITERAL("foo");
+static CharBuf boffo = ZCB_LITERAL("boffo");
+static CharBuf foo_boffo = ZCB_LITERAL("foo/boffo");
+
+static void
+test_all(TestBatch *batch)
+{
+ RAMFolder *folder = RAMFolder_new(NULL);
+ FileHandle *fh;
+ RAMDirHandle *dh;
+ CharBuf *entry;
+ bool_t saw_foo = false;
+ bool_t saw_boffo = false;
+ bool_t foo_was_dir = false;
+ bool_t boffo_was_dir = false;
+ int count = 0;
+
+ RAMFolder_MkDir(folder, &foo);
+ fh = RAMFolder_Open_FileHandle(folder, &boffo, FH_CREATE | FH_WRITE_ONLY);
+ DECREF(fh);
+ fh = RAMFolder_Open_FileHandle(folder, &foo_boffo,
+ FH_CREATE | FH_WRITE_ONLY );
+ DECREF(fh);
+
+ dh = RAMDH_new(folder);
+ entry = RAMDH_Get_Entry(dh);
+ while (RAMDH_Next(dh)) {
+ count++;
+ if (CB_Equals(entry, (Obj*)&foo)) {
+ saw_foo = true;
+ foo_was_dir = RAMDH_Entry_Is_Dir(dh);
+ }
+ else if (CB_Equals(entry, (Obj*)&boffo)) {
+ saw_boffo = true;
+ boffo_was_dir = RAMDH_Entry_Is_Dir(dh);
+ }
+ }
+ ASSERT_INT_EQ(batch, 2, count, "correct number of entries");
+ ASSERT_TRUE(batch, saw_foo, "Directory was iterated over");
+ ASSERT_TRUE(batch, foo_was_dir,
+ "Dir correctly identified by Entry_Is_Dir");
+ ASSERT_TRUE(batch, saw_boffo, "File was iterated over");
+ ASSERT_FALSE(batch, boffo_was_dir,
+ "File correctly identified by Entry_Is_Dir");
+
+ {
+ u32_t refcount = RAMFolder_Get_RefCount(folder);
+ RAMDH_Close(dh);
+ ASSERT_INT_EQ(batch, RAMFolder_Get_RefCount(folder), refcount - 1,
+ "Folder reference released by Close()");
+ }
+
+ DECREF(dh);
+ DECREF(folder);
+}
+
+void
+TestRAMDH_run_tests()
+{
+ TestBatch *batch = Test_new_batch("TestRAMDirHandle", 6, NULL);
+
+ PLAN(batch);
+ test_all(batch);
+
+ batch->destroy(batch);
+}
+
+/* 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/Test/Store/TestRAMDirHandle.c
------------------------------------------------------------------------------
svn:eol-style = native

Modified: lucene/lucy/trunk/core/Lucy/Test/Store/TestRAMFolder.c
URL: http://svn.apache.org/viewvc/lucene/lucy/trunk/core/Lucy/Test/Store/TestRAMFolder.c?rev=883826&r1=883825&r2=883826&view=diff
==============================================================================
--- lucene/lucy/trunk/core/Lucy/Test/Store/TestRAMFolder.c (original)
+++ lucene/lucy/trunk/core/Lucy/Test/Store/TestRAMFolder.c Tue Nov 24 19:24:46 2009
@@ -7,6 +7,8 @@

#include "Lucy/Test/Store/TestRAMFolder.h"
#include "Lucy/Store/RAMFolder.h"
+#include "Lucy/Store/DirHandle.h"
+#include "Lucy/Store/RAMDirHandle.h"
#include "Lucy/Store/RAMFileHandle.h"

static CharBuf foo = ZCB_LITERAL("foo");
@@ -151,6 +153,17 @@
}

static void
+test_Local_Open_Dir(TestBatch *batch)
+{
+ RAMFolder *folder = RAMFolder_new(NULL);
+ DirHandle *dh = Folder_Local_Open_Dir(folder);
+ ASSERT_TRUE(batch, dh && DH_Is_A(dh, RAMDIRHANDLE),
+ "Local_Open_Dir returns a RAMDirHandle");
+ DECREF(dh);
+ DECREF(folder);
+}
+
+static void
test_Local_Open_FileHandle(TestBatch *batch)
{
RAMFolder *folder = RAMFolder_new(NULL);
@@ -450,7 +463,7 @@
void
TestRAMFolder_run_tests()
{
- TestBatch *batch = Test_new_batch("TestRAMFolder", 97, NULL);
+ TestBatch *batch = Test_new_batch("TestRAMFolder", 98, NULL);

PLAN(batch);
test_Initialize_and_Check(batch);
@@ -458,6 +471,7 @@
test_Local_Is_Directory(batch);
test_Local_Find_Folder(batch);
test_Local_MkDir(batch);
+ test_Local_Open_Dir(batch);
test_Local_Open_FileHandle(batch);
test_Local_Delete(batch);
test_Rename(batch);

Modified: lucene/lucy/trunk/perl/lib/Lucy/Test.pm
URL: http://svn.apache.org/viewvc/lucene/lucy/trunk/perl/lib/Lucy/Test.pm?rev=883826&r1=883825&r2=883826&view=diff
==============================================================================
--- lucene/lucy/trunk/perl/lib/Lucy/Test.pm (original)
+++ lucene/lucy/trunk/perl/lib/Lucy/Test.pm Tue Nov 24 19:24:46 2009
@@ -49,6 +49,9 @@
else if (strEQ(package, "TestIOPrimitives")) {
lucy_TestIOPrimitives_run_tests();
}
+ else if (strEQ(package, "TestRAMDirHandle")) {
+ lucy_TestRAMDH_run_tests();
+ }
else if (strEQ(package, "TestRAMFileHandle")) {
lucy_TestRAMFH_run_tests();
}

Added: lucene/lucy/trunk/perl/t/core/061-ram_dir_handle.t
URL: http://svn.apache.org/viewvc/lucene/lucy/trunk/perl/t/core/061-ram_dir_handle.t?rev=883826&view=auto
==============================================================================
--- lucene/lucy/trunk/perl/t/core/061-ram_dir_handle.t (added)
+++ lucene/lucy/trunk/perl/t/core/061-ram_dir_handle.t Tue Nov 24 19:24:46 2009
@@ -0,0 +1,6 @@
+use strict;
+use warnings;
+
+use Lucy::Test;
+Lucy::Test::run_tests("TestRAMDirHandle");
+

Propchange: lucene/lucy/trunk/perl/t/core/061-ram_dir_handle.t
------------------------------------------------------------------------------
svn:eol-style = native
reply

Search Discussions

Related Discussions

Discussion Navigation
viewthread | post

1 user in discussion

Marvin: 1 post