>> That's exactly the function I'm using.  My use case is iterating
>> through a tree-like structure, where each node holds a dict of values
>> and/or branches.
>
> If the nodes are cdef classes, it should be enough to type the attribute
> as "cdef dict" and use the iter*() dict methods in your code. Especially
> the improvement compared to the plain (untyped) iteritems() method call
> (which requires redundant tuple packing and unpacking) should be
> substantial.
>
>> When I encounter a branch, I iterate recursively
>> over that branch before continuing iteration locally.  The best way of
>> implementing this, at least that I found, is to use a stack of node
>> dictionaries references + position variables and invoke PyDict_Next()
>> while pushing/popping as needed.
>
> That sounds like you are not using a recursive function here. If so, why not?

Sorry, I should have been clearer.  I'm writing an iterator class used
to iterate through the tree, so I need to preserve state at every
level between returns of __next__().  This stack approach is what I
immediately thought of, and while I could use recursion to traverse
the state stack, I ended up just using a loop.

>> I now implemented it using the intermediate variable method given
>> above.  It works great.
>
> That's why I implemented that loop optimisation. :)

Thanks!  I use that all over the place in my code.

>> BTW, this solution:
>>
>>> You can do <PyObject*>a, so do &(<PyObject*>a) to get a PyObject**
>>
>> gives me the error message
>>
>> /home/hoytak/workspace/paramtree/paramtree/paramtree.pyx:648:31:
>> Taking address of non-lvalue
>>
>> Is that a bug?
>
> Hmm, I don't see an obvious problem with this, so it looks like a bug.
> Could you file a bug report with a test case that shows how to reproduce
> this?

Okay, I'll do that, though I don't have time til later today.

--Hoyt

++++++++++++++++++++++++++++++++++++++++++++++++
+ Hoyt Koepke
+ University of Washington Department of Statistics
+ http://www.stat.washington.edu/~hoytak/
+ [email protected]
++++++++++++++++++++++++++++++++++++++++++
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev

Reply via email to