Tuesday, February 09

Geek

TreeDict

Well, that's annoying.  I just wrote one of these to speed up the Minx template parser, but this one is probably faster (it's a Cython module) and certainly better documented.

The functionality is identical as far as I can see, but I called mine a DictTree.

Actually, no, mine has one extra feature: It allows you to reference a value using mapping-style lookup (tags['a.b']) that would be a subtree in an attribute-style lookup.  If tags.a.b.c is set, tags.a.b is necessarily the tree containing b; try anything else and you blow yourself out of the water.  But tags['a.b'] can be anything you like.

I need to do that because I designed the Minx template language that way.  (Oops.)  It lets you reference, for example, post.date as a date value, and also post.date.month to find just the month of the date of the post.  You can't do that with dicts; you could probably do it with a smarter class, but bang would go my generality.

Since that trick is used on both dates and strings, I'd need to make all my dates and strings into custom classes to make the attribute syntax work directly, and that's just too messy to contemplate.

Posted by: Pixy Misa at 02:09 AM | No Comments | Add Comment | Trackbacks (Suck)
Post contains 200 words, total size 1 kb.

Comments are disabled. Post is locked.
44kb generated in CPU 0.0183, elapsed 0.1024 seconds.
54 queries taking 0.0949 seconds, 337 records returned.
Powered by Minx 1.1.6c-pink.