| Jon Stewart on Fri, 3 Dec 2004 15:48:20 -0600 (CST) |
[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
| Re: [nimh-dev] More stuff |
> 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", a > nd > 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 I think it will be easier if it's like this: 1. ['cur', 8, '9-11', 'foo'] 2. [4, 8, '9-11', 7, '10-12'] # list remains flat 3. [8, '9-11', 7, '10-12'] --> [(4, 5)] 4. ['9-11', 7, '10-12'] --> [(4, 5), (8, 9)] 5. [7, '10-12'] --> [(4, 5), (8, 12)] 6. ['10-12'] --> [(4, 5), (7, 12)] 7. [] --> [(4, 5), (7, 13)] Numeric tokens are popped off the first list and a second list of ranges is created. But my brain has been warped by too many years of C++'s static type-checking, so my preference may be due to my inability to think about collections of different types. > 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]] No, it should store [1, 500] (or [1, 501]). Checking for existence later on will keep the code cleaner. Jon -- Jon Stewart Advanced Los Angeles C++ stew1@xxxxxxxxxxx http://www.alacpp.org _______________________________________________ nimh-dev mailing list nimh-dev@xxxxxxxxxxx http://lists.ellipsis.cx/mailman/listinfo/nimh-dev