| Tom Plagge on Fri, 3 Dec 2004 15:26:10 -0600 (CST) |
[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
| Re: [nimh-dev] More stuff |
> Thus spake "Jon Stewart": > > > MH treats sequences like sets. E.g. 'scan 2 1 1' will show you the scan > > > for 1, followed by the scan for 2. I like it that way. I wish it were > > > also a way to apply set-theoretic operations other than union and negatio > n, > > > though. Say I want to list all messages in foo and bar, e.g., I should be > > > able to 'scan foo&bar'. As opposed to scan foo ; scan bar? :) > > Hmm. Then I guess we will need to calculate the sequence upfront. In that > > case, it's probably best to have a sorted list of range tuples, [beg, > > end). Constructing the list isn't too hard. You throw the first specified > > range in the list and, if there are any others, you go through the list > > for each one (it's a quadratic algorithm) and either insert the range in > > its rightful place -- if it's disjoint with existing ranges -- or expand > > the existing ranges if there are overlaps. I can think of a pythony simple way to do this. Say you specified a sequence "cur 8 9-11 foo" where foo is an existing sequence consisting of "7 10-12", and cur is 4. 1. ['cur', 8, '9-11', 'foo'] <-- split by whitespace 2. [4, 8, '9-11', [7, '10-12']] <-- parse tokens (foo, cur) 3. [4, 8, [9, 11], [7, [10, 12]]] <-- parse ranges 4. [4, 8, [9, 11], 7, [10, 12]] <-- eliminate sublists 5. [4, 8, [9, 11], 7, 12] <-- eliminate overlap 6. [4, 7, 8, [9, 11], 12] <-- sort Then 5. would be the final form that was stored in sequence.seq. No need to wrap up [7, 8, [9,11], 12] into [7,12]; it's plenty easy to deal with in its current form. For step 3, you'd have to take a piecewise continuous range and split it up into continuous ranges; for instance, if your folder contains messages 1-400 and 402-500, and you specify 1-500, it should store the value [[1,400],[402,500]] ________________________________________________________________________ Tom Plagge UC Berkeley Physics Dept. 351 LeConte Hall Voice: (510) 643-1650 Berkeley, CA 94720 Email: tplagge@xxxxxxxxxxxxxxxxx ________________________________________________________________________ _______________________________________________ nimh-dev mailing list nimh-dev@xxxxxxxxxxx http://lists.ellipsis.cx/mailman/listinfo/nimh-dev