all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Tim X <timx@nospam.dev.null>
To: help-gnu-emacs@gnu.org
Subject: Re: Datastructure for table
Date: Fri, 15 Jan 2010 11:23:08 +1100	[thread overview]
Message-ID: <87fx68cj2r.fsf@lion.rapttech.com.au> (raw)
In-Reply-To: mailman.1435.1263510168.18930.help-gnu-emacs@gnu.org

Johan Andersson <johan.rejeep@gmail.com> writes:

> Hey,
>
> I have an Org-table looking like this:
> | person | car     | wife      |
> | John     | Volvo | Susan |
> | Peter    | BMW  | Greta   |
> | Stefan  | Golf    | Althea  |
>
> I want to parse this so that I get one object per row (execpt the
> header, which defines the keys). So if I for example have the first
> object, I want to be able to fetch the value of some column given the
> header key. The table is dynamic and can have any number of columns
> and the header names differ.
>
> What kind of datastructure would fit for this? I can think of a few
> that may work (Hash-table, Struct and Plist), but none that fit very
> well.
>

Well, its difficult to say what structure would work best because this
really depends on what you plan to do with the data and the relative
frequencies of the various operations you will be performing. 

Additional options you didn't mention could include 

           1 Association lists. Keys would be columns. Has the advantage
           of being able to use assoc etc to get/set values
           2 Nested lists. First sublist could be the list of column
           names. Subsequent lists could be each record. 
           4. Objects i.e. EIEIO (Enhanced Implementation of Emacs
           Interpreted Objects)

Assuming the tables will vary re: columns and column names and assuming
as these are org based tables, there not going to be that large, I would
be tempted to go with alist or nested lists. However, it really depends
on what you plan to do with the data. If your not going to be updating
the values much, nested lists could be pretty easy to implement.
However, if you need access to specific column values, alist may be
better. 

Choose the structure that makes the most frequent or most complex
operations easiest to code and maintain. 

Tim



-- 
tcross (at) rapttech dot com dot au


       reply	other threads:[~2010-01-15  0:23 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <mailman.1435.1263510168.18930.help-gnu-emacs@gnu.org>
2010-01-15  0:23 ` Tim X [this message]
2010-01-15 16:45   ` Datastructure for table Johan Andersson
2010-01-14 22:00 Johan Andersson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87fx68cj2r.fsf@lion.rapttech.com.au \
    --to=timx@nospam.dev.null \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.