From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Tim X Newsgroups: gmane.emacs.help Subject: Re: Datastructure for table Date: Fri, 15 Jan 2010 11:23:08 +1100 Organization: Rapt Technologies Message-ID: <87fx68cj2r.fsf@lion.rapttech.com.au> References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Trace: ger.gmane.org 1263516055 9165 80.91.229.12 (15 Jan 2010 00:40:55 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 15 Jan 2010 00:40:55 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Fri Jan 15 01:40:48 2010 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1NVaF4-0007cC-9I for geh-help-gnu-emacs@m.gmane.org; Fri, 15 Jan 2010 01:40:46 +0100 Original-Received: from localhost ([127.0.0.1]:51649 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NVaF4-0000UZ-VB for geh-help-gnu-emacs@m.gmane.org; Thu, 14 Jan 2010 19:40:46 -0500 Original-Path: news.stanford.edu!usenet.stanford.edu!news.glorb.com!news2.glorb.com!news.astraweb.com!border1.newsrouter.astraweb.com!not-for-mail Original-Newsgroups: gnu.emacs.help User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1.90 (gnu/linux) Cancel-Lock: sha1:m+TA5Uptra/OkD2OC0iOeb7axXs= Original-Lines: 51 Original-NNTP-Posting-Host: e17520fb.news.astraweb.com Original-X-Trace: DXC=I[foo:7I^DMYGe3 Original-Xref: news.stanford.edu gnu.emacs.help:176157 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:71228 Archived-At: Johan Andersson 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