Skip to main content.
September 26th, 2006

n-level, m-width tree parsing

I have been programming for several years, and have been exposed to all sorts of problems along the way. However, Friday was about my first opportunity to actually use a tree traversal in a ‘real’ project, not just one assigned by a professor.

As most *nix types are aware, you can set up an aliases file to map addresses onto real world users. The problem with this file is that aliases can get stale, new aliases can be made that end up totally encompassing old ones (unintentionally), etc.

So, the request came about to be able to use a webform to look up where, exactly, an alias points. So, into our work order ticketing system it went, and I started working on it on paper Thursday evening. Turns out that it is not in fact to be a graph problem but rather a tree problem. This is a Good Thing™. Graph problems aren’t horrible to work with, but they are substantially more complex than tree problems.

The general form of the /etc/aliases file is listed above, but I left out an important caveat - aliases can point to a file of delimited targets via the :include: directive. To make a medium-length story pretty short, to parse the aliases file, every line needs to be read, and then tokenized to display the results of a search, recursively.

I suppose you could traverse the tree using a loop-based approach, but heaven help you to handle the corner cases. The only I have to track in traversing the tree is what the most recently checked alias was, and advance to the next one in the list when the check on that iteration is over.

Overall, it turned out to be a really easy to write script, and it’s now live on our site. If you are Shodor staff, you can play with it here.

Posted by wmyers in work

This entry was posted on Tuesday, September 26th, 2006 at 16:29 and is filed under work. You can follow any responses to this entry through the comments RSS 2.0 feed. You can leave a response, or trackback from your own site.

9 Responses to “n-level, m-width tree parsing”

  1. wmyers says:

    Upon further reflection, the alias parsing script wasn’t technically a tree problem - it was more a non-looping, digraph problem, but one that can be treated as a tree

  2. Buy phentermine no prescription bloghoster. says:

    Buy phentermine no prescription bloghoster….

    Buy phentermine without a prescription. Buy phentermine online without a prescription. Buy phentermine without prescription. Buy phentermine online without prescription. Buy no phentermine prescription. Where to buy phentermine without prescription. Bu…

  3. Buy cheap phentermine. says:

    Buy cheap phentermine mg tabs lowest prices….

    Buy cheap phentermine mg tabs lowest prices. Buy phentermine online cheap without prescription. Buy phentermine online without prescription cheap. Buy cheap phentermine now save. Buy cheap phentermine. Phentermine buy cheap online….

  4. Phentermine diet pills. says:

    Phentermine diet pills….

    Phentermine diet pills….

  5. Buy phentermine online 37.5mg no prescription. says:

    Phentermine 37 5mg….

    Phentermine 37 5mg. Phentermine 37 5mg us pharmacies….

  6. kanders says:

    Hello…

    My life,vist it http://blog.extra.by/xiangdress/ ,Thanks….

  7. Chantelles says:

    Hello…

    My life,vist it http://xiangcai.bloginthedark.com/2011/09/02/mickey-mouse-and-minnie-wedding-cakes/ ,Thanks….

  8. kjersic says:

    Hello…

    My life,vist it http://deborahr11.eklablog.com/ ,Thanks….

  9. Sterkers says:

    Great One…

    Everyone can get music from internet or from pirated cds at very low rate. Then how the music industry can still survive in india. And if downloading music from free site like songs.pk is illegal then why govt. do not put ban on these sites.. @shobha- …

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>