Repository: lucy-clownfish
Updated Branches:
  refs/heads/clone_class_registry [created] 859ee7e1b


Implement iterator for LockFreeRegistry


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

Branch: refs/heads/clone_class_registry
Commit: bfde91c3a34fcfbf4965046f0ceb9955f7c17118
Parents: c1d89c3
Author: Nick Wellnhofer <[email protected]>
Authored: Sun Aug 3 16:06:05 2014 +0200
Committer: Nick Wellnhofer <[email protected]>
Committed: Sun Aug 3 17:38:04 2014 +0200

----------------------------------------------------------------------
 runtime/core/Clownfish/LockFreeRegistry.c   | 51 ++++++++++++++++++++++++
 runtime/core/Clownfish/LockFreeRegistry.cfh | 17 ++++++++
 2 files changed, 68 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/bfde91c3/runtime/core/Clownfish/LockFreeRegistry.c
----------------------------------------------------------------------
diff --git a/runtime/core/Clownfish/LockFreeRegistry.c 
b/runtime/core/Clownfish/LockFreeRegistry.c
index fab4f54..577ecb0 100644
--- a/runtime/core/Clownfish/LockFreeRegistry.c
+++ b/runtime/core/Clownfish/LockFreeRegistry.c
@@ -15,6 +15,7 @@
  */
 
 #define C_CFISH_LOCKFREEREGISTRY
+#define C_CFISH_LFREGITERATOR
 #define CFISH_USE_SHORT_NAMES
 
 #include "Clownfish/LockFreeRegistry.h"
@@ -148,4 +149,54 @@ LFReg_Destroy_IMP(LockFreeRegistry *self) {
     SUPER_DESTROY(self, LOCKFREEREGISTRY);
 }
 
+/**********************************************************************/
+
+LFRegIterator*
+LFRegIter_new(LockFreeRegistry *registry) {
+    LFRegIterator *self = (LFRegIterator*)Class_Make_Obj(LFREGITERATOR);
+    return LFRegIter_init(self, registry);
+}
+
+LFRegIterator*
+LFRegIter_init(LFRegIterator *self, LockFreeRegistry *registry) {
+    self->registry = (LockFreeRegistry*)INCREF(registry);
+    self->tick     = 0;     // Next tick.
+    self->entry    = NULL;  // Previous entry.
+    return self;
+}
+
+bool
+LFRegIter_Next_IMP(LFRegIterator *self, Obj **key, Obj**value) {
+    size_t      tick  = self->tick;
+    LFRegEntry *entry = (LFRegEntry*)self->entry;
+
+    if (entry) {
+        entry = entry->next;
+    }
+
+    LockFreeRegistry  *registry = self->registry;
+    size_t             capacity = registry->capacity;
+    LFRegEntry       **entries  = registry->entries;
+
+    while (!entry && tick < capacity) {
+        entry = entries[tick++];
+    }
+
+    self->tick  = tick;
+    self->entry = entry;
+
+    if (!entry) { return false; }
+
+    if (key)   { *key   = entry->key;   }
+    if (value) { *value = entry->value; }
+
+    return true;
+}
+
+void
+LFRegIter_Destroy_IMP(LFRegIterator *self) {
+    DECREF(self->registry);
+
+    SUPER_DESTROY(self, LFREGITERATOR);
+}
 

http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/bfde91c3/runtime/core/Clownfish/LockFreeRegistry.cfh
----------------------------------------------------------------------
diff --git a/runtime/core/Clownfish/LockFreeRegistry.cfh 
b/runtime/core/Clownfish/LockFreeRegistry.cfh
index 2061a23..cc8be8e 100644
--- a/runtime/core/Clownfish/LockFreeRegistry.cfh
+++ b/runtime/core/Clownfish/LockFreeRegistry.cfh
@@ -45,4 +45,21 @@ class Clownfish::LockFreeRegistry nickname LFReg inherits 
Clownfish::Obj {
     Destroy(LockFreeRegistry *self);
 }
 
+class Clownfish::LFRegIterator nickname LFRegIter inherits Clownfish::Obj {
+    LockFreeRegistry *registry;
+    size_t            tick;
+    void             *entry;
+
+    inert incremented LFRegIterator*
+    new(LockFreeRegistry *registry);
+
+    inert LFRegIterator*
+    init(LFRegIterator *self, LockFreeRegistry *registry);
+
+    public bool
+    Next(LFRegIterator *self, Obj **key, Obj**value);
+
+    public void
+    Destroy(LFRegIterator *self);
+}
 

Reply via email to