<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Anstis, Michael (M.) wrote:
<blockquote
cite="mid:6CE83AFC8500B641AE00AC1674A3B4AC037EF843@eu1wam08.warley.ford.com"
type="cite">
<pre wrap="">Wouldn't the best approach be to get the FactHandles iterator and retact
them from working memory rather than removing them through the iterator?
Iterator itr = wm.iterateFactHandles();
While(itr.next()) {
        FactHandle h = itr.next();
        wm.retract(h);
}
This would ensure truth maintenance is preserved.
</pre>
</blockquote>
Actually I'm not sure that would be safe.... the objects and the
handles are in the same hashtable. Those internal data structures where
built for performance and lightweightness, not thread safeness and
mutability. If you actually look we have an internal, fast, iterator
which we simple adapt to a slower java.util.Iterator. At the moment
none of our iterators are thread safe, but I do see a valid use case
here, we will have to think on it for the next major release - cleam
implementation patch welcome with unit tests :) I'm less concerned
about the iterator adapter performance, but I cannot compromise on the
performance of our internal iterators.<br>
<br>
public static class HashTableIterator<br>
implements<br>
Iterator {<br>
<br>
private static final long serialVersionUID = 400L;<br>
<br>
private AbstractHashTable hashTable;<br>
private Entry[] table;<br>
private int row;<br>
private int length;<br>
private Entry entry;<br>
<br>
public HashTableIterator(final AbstractHashTable hashTable) {<br>
this.hashTable = hashTable;<br>
}<br>
<br>
/* (non-Javadoc)<br>
* @see org.drools.util.Iterator#next()<br>
*/<br>
public Object next() {<br>
if ( this.entry == null ) {<br>
// keep skipping rows until we come to the end, or find
one that is populated<br>
while ( this.entry == null ) {<br>
this.row++;<br>
if ( this.row == this.length ) {<br>
return null;<br>
}<br>
this.entry = this.table[this.row];<br>
}<br>
} else {<br>
this.entry = this.entry.getNext();<br>
if ( this.entry == null ) {<br>
this.entry = (Entry) next();<br>
}<br>
}<br>
<br>
return this.entry;<br>
}<br>
<br>
/* (non-Javadoc)<br>
* @see org.drools.util.Iterator#reset()<br>
*/<br>
public void reset() {<br>
this.table = this.hashTable.getTable();<br>
this.length = this.table.length;<br>
this.row = -1;<br>
this.entry = null;<br>
}<br>
}<br>
<blockquote
cite="mid:6CE83AFC8500B641AE00AC1674A3B4AC037EF843@eu1wam08.warley.ford.com"
type="cite">
<pre wrap="">
-----Original Message-----
From: <a class="moz-txt-link-abbreviated" href="mailto:rules-users-bounces@lists.jboss.org">rules-users-bounces@lists.jboss.org</a>
[<a class="moz-txt-link-freetext" href="mailto:rules-users-bounces@lists.jboss.org">mailto:rules-users-bounces@lists.jboss.org</a>] On Behalf Of Godmar Back
Sent: 05 October 2007 16:40
To: Rules Users List
Subject: Re: [rules-users] does WorkingMemory.iterator support remove()?
Thanks - consider supporting it for efficiency. (Otherwise, removing a
set of facts from working memory requires a temporary container to
hold the facts to be removed.)
- Godmar
On 10/5/07, Mark Proctor <a class="moz-txt-link-rfc2396E" href="mailto:mproctor@codehaus.org"><mproctor@codehaus.org></a> wrote:
</pre>
<blockquote type="cite">
<pre wrap="">Godmar Back wrote:
</pre>
<blockquote type="cite">
<pre wrap="">Does the iterator returned by WorkingMemory.iterator support remove()?
I checked the javadoc and the Drools manual, but may have missed it.
</pre>
</blockquote>
<pre wrap="">If you try it you'll get an exception thrown
</pre>
</blockquote>
<pre wrap=""><!---->"UnsupportedOperationException"
</pre>
<pre wrap=""><!----><a class="moz-txt-link-freetext" href="http://anonsvn.labs.jboss.com/labs/jbossrules/trunk/drools-core/src/main/jav">http://anonsvn.labs.jboss.com/labs/jbossrules/trunk/drools-core/src/main/jav</a>
a/org/drools/util/JavaIteratorAdapter.java
</pre>
<blockquote type="cite">
<blockquote type="cite">
<pre wrap="">Please answer and augment documentation.
- Godmar
_______________________________________________
rules-users mailing list
<a class="moz-txt-link-abbreviated" href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a>
<a class="moz-txt-link-freetext" href="https://lists.jboss.org/mailman/listinfo/rules-users">https://lists.jboss.org/mailman/listinfo/rules-users</a>
</pre>
</blockquote>
<pre wrap="">_______________________________________________
rules-users mailing list
<a class="moz-txt-link-abbreviated" href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a>
<a class="moz-txt-link-freetext" href="https://lists.jboss.org/mailman/listinfo/rules-users">https://lists.jboss.org/mailman/listinfo/rules-users</a>
</pre>
</blockquote>
<pre wrap=""><!---->_______________________________________________
rules-users mailing list
<a class="moz-txt-link-abbreviated" href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a>
<a class="moz-txt-link-freetext" href="https://lists.jboss.org/mailman/listinfo/rules-users">https://lists.jboss.org/mailman/listinfo/rules-users</a>
</pre>
<pre wrap="">
<hr size="4" width="90%">
_______________________________________________
rules-users mailing list
<a class="moz-txt-link-abbreviated" href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a>
<a class="moz-txt-link-freetext" href="https://lists.jboss.org/mailman/listinfo/rules-users">https://lists.jboss.org/mailman/listinfo/rules-users</a>
</pre>
</blockquote>
<br>
</body>
</html>