caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: John Max Skaller <skaller@ozemail.com.au>
To: Matt Gushee <matt@gushee.net>
Cc: caml-list@pauillac.inria.fr
Subject: Re: [Caml-list] Multi-keyed lookup table?
Date: Fri, 08 Aug 2003 08:19:36 +1000	[thread overview]
Message-ID: <3F32D078.7060705@ozemail.com.au> (raw)
In-Reply-To: <20030807194135.GB21983@swordfish>

Matt Gushee wrote:

> Hello, all--
> 
> I am trying to decide on a data structure that allows efficient lookup
> of fonts according to various font properties. I am thinking that the
> data structures describing fonts will be something like this:
 
 
> So, does anyone have an idea what sort of data structure would work
> best?
> 
> TIA for your suggestions.

Since you have 'arbitrary' keying, the ideal data structure
is clearly a relational database :-)

I personally suggest the brain dead equivalent, assuming
you have a *finite* set of fonts available: an array of
all the fonts in random order, and just use a linear search.

It's likely for a small number of fonts (<1000) that this
is faster than any other method due to caching issues:
arrays outperform ALL other data structures for small
number of entries.

You  might optimise this in two ways: cache some results,
on the basis the same request is made many times in one
program. [possibly making the cache persistent]

And you might be able to index the most commonly
used keys, such as font-family...much like you'd do in
a database.

You might gain some advantage in the comparisons
for equality using the == operator (physical equality)
provided you can ensure equal values have the same
physical representation (eg:

	let helvetica = "Helvetica"

	[.. helvetica .. ]
	[.. helvetica .. ]

which would mean you'd have to match the incoming request against the
available font-families:

	let bff = match ff with | "Helvetica" -> helvetica ..

so you can do the comparisons like

	if bff == font.(i).ff ......

This is an address comparison, and is faster than a string
comparison.

There's a good chance the comparisons will dominate,
rather than the time taken to read each entry from
the database. That means an index would give you an
order of magnitude speed improvement .. in theory ..
but its hard to know which keys to index. I think I'd
be building a model with no indexes, encapsulating
it so that you can add indexes transparently later.
Then profile/performance test to see where the bottlenecks
are... I suspect it is client dependent (some clients will
key by font-family, other may choose font class ...)

-- 
John Max Skaller, mailto:skaller@ozemail.com.au
snail:10/1 Toxteth Rd, Glebe, NSW 2037, Australia.
voice:61-2-9660-0850


-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


  parent reply	other threads:[~2003-08-07 22:19 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-08-07 19:41 Matt Gushee
2003-08-07 20:16 ` Brian Hurt
2003-08-07 21:49   ` Yaron Minsky
2003-08-07 22:26     ` John Max Skaller
     [not found]       ` <D4DBD8568F05D511A1C20002A55C008C11AC05E6@uswaumsx03medge.med.ge.com>
2003-08-08 21:30         ` Matt Gushee
2003-08-08 22:13           ` Brian Hurt
     [not found]           ` <005d01c35e51$7c927200$6628f9c1@zofo>
2003-08-09 16:57             ` [Caml-list] Array.filter (was Multi-keyed lookup table?) Matt Gushee
2003-08-09 18:48               ` ijtrotts
2003-08-10 19:53                 ` Michal Moskal
2003-08-10  2:34                   ` ijtrotts
2003-08-11  5:48                     ` David Brown
2003-08-10 18:53                       ` ijtrotts
2003-08-10 20:23                   ` Marcin 'Qrczak' Kowalczyk
2003-08-10  2:37                     ` ijtrotts
     [not found]                   ` <200308102222.16369.qrczak@knm.org.pl>
2003-08-10 20:43                     ` Michal Moskal
2003-08-10 21:59                       ` Ville-Pertti Keinonen
2003-08-10 20:55                 ` [Caml-list] Array.filter Jean-Baptiste Rouquier
2003-08-11  9:46                   ` Michal Moskal
2003-08-10 22:29                 ` [Caml-list] Array.filter (was Multi-keyed lookup table?) Shawn Wagner
2003-08-11 11:51           ` [Caml-list] Multi-keyed lookup table? Remi Vanicat
2003-08-07 22:19 ` John Max Skaller [this message]
2003-08-12  6:34   ` Florian Hars
2003-08-12  9:58     ` Michael Wohlwend

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=3F32D078.7060705@ozemail.com.au \
    --to=skaller@ozemail.com.au \
    --cc=caml-list@pauillac.inria.fr \
    --cc=matt@gushee.net \
    /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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).