caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: "Seth J. Fogarty" <sfogarty@gmail.com>
To: caml-list <caml-list@inria.fr>
Subject: References, compact bollean values (and other questions)
Date: Thu, 3 Nov 2005 17:34:06 -0600	[thread overview]
Message-ID: <c7ee61120511031534w56d2ec4dj3d21ae08a1c70de9@mail.gmail.com> (raw)

So I am implementing a DPLL procedure for CNF sat. This is the first
time, for me, that I've been programming in ocaml that speed is
absolutely critical. I will have a small code base running for
literally days on end. Thus I have some speed/efficiently questions.

First question: I notice references are implemented using mutable
records. Does this imply tuples of references are slower than mutable
records?
I.E.
type a = int ref * int ref * int ref
vs
type a = {mutable a : int; mutable b : int; mutable c : int}

Second: I need a non-varient data type.
It needs to store three integers and six mutable boolean.
I would like this to be done as compactly as possible, ideally in 128
contiguious bits.

Will either records or tuples store these contiguously?
If I use tuples and references, will ocamlc 'compact' booleans, or
give them 32 bits each? I think this is highly unlikely.
If I use records, will ocamlc 'compact' booleans, or give them 32 bits each?
If I use an integer to represent all six booleans, is there an easy
way to gain access to/flip a single bit? I can only find shifting
operations in pervasives

Third question: How aggressive/intelligent is the ocamlc inlining?
Should I worry about inlining functions that I expect to be used
millions of times?

Fourth question: If you got this far and still want to help, is there
anything obviously wrong with the following imperitive linked list
implementation in terms of speed? I expect traversal to be rare. I
have defined add, delete, and insert operations (that are easily
undoable).

type 'a ll = Nul | Node of 'a * 'a ll ref | Head of 'a ll ref
type 'a llptr = 'a ll * 'a ll (*the predecessor and the node pointed to.*)
type 'a undo = 'a ll ref * 'a ll
let undo ((a, b) : 'a undo) = a := b
let delete (llptr : 'a llptr) : 'a undo =
   match llptr with
     |(Head b, (Node (_, b') as deleted))
     |(Node (_, b), (Node (_, b') as deleted)) -> b := !b'; (b, deleted)
     |_ -> failwith "delete"

--
Seth Fogarty             sfogarty@[gmail.com|rice.edu|livejournal]
Neep-neep at large    AIM: Sorrath
"I know there are people in this world who do not love their fellow
human beings - and I hate people like that" --Tom Lehrer.


             reply	other threads:[~2005-11-03 23:34 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-11-03 23:34 Seth J. Fogarty [this message]
2005-11-04  0:20 ` [Caml-list] " Brian Hurt
2005-11-04  2:39   ` skaller

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=c7ee61120511031534w56d2ec4dj3d21ae08a1c70de9@mail.gmail.com \
    --to=sfogarty@gmail.com \
    --cc=caml-list@inria.fr \
    /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).