From: "Török Edwin" <edwin+ml-ocaml@etorok.net>
To: caml-list@inria.fr
Subject: Re: [Caml-list] Efficient scanning of large strings from files
Date: Sun, 18 Mar 2012 23:11:23 +0200 [thread overview]
Message-ID: <4F664F7B.6020405@etorok.net> (raw)
In-Reply-To: <20120316154901.76602deb@caladan.esterel-technologies.com>
On 03/16/2012 04:49 PM, Jérémie Dimino wrote:
> Le Fri, 16 Mar 2012 14:03:38 +0100,
> Philippe Veber <philippe.veber@gmail.com> a écrit :
>
>> Say that you'd like to search a regexp on a file with lines so long
>> that you'd rather not load them entirely at once. If you can bound
>> the size of a match by k << length of a line, then you know that you
>> can only keep a small portion of the line in memory to search the
>> regexp. Typically you'd like to access substrings of size k from left
>> to right. I guess such a thing should involve buffered inputs and
>> avoid copying strings as much as possible. My question is as follows:
>> has anybody written a library to access these substrings gracefully
>> and with decent performance? Cheers,
>
> You can use a non-backtracking regexp library to find offsets of the
> substrings, then seek in the file to extract them. You can use for
> example the libre library from Jérôme Vouillon [1]. It only accept
> strings as input but it would be really easy to make it work on input
> channels (just replace "s.[pos]" by "input_char ic").
>
> [1] http://sourceforge.net/projects/libre/
> https://github.com/avsm/ocaml-re.git
>
A nice library for regular expression matching is LibTRE (BSD licensed),
and it has a way to parse arbitrary data with callbacks:
http://laurikari.net/tre/documentation/reguexec/
According to the paper it is also good at finding substring matches
with its tagged NFA:
http://laurikari.net/ville/regex-submatch.pdf
If you don't use back-references (!tre_have_backrefs) then it guarantees linear-time matching.
I couldn't find an OCaml wrapper for it, but should be simple enough to write one.
Best regards,
--Edwin
next prev parent reply other threads:[~2012-03-18 21:11 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-03-16 13:03 Philippe Veber
2012-03-16 14:14 ` Edgar Friendly
2012-03-16 14:48 ` Philippe Veber
2012-03-16 17:02 ` Edgar Friendly
2012-03-19 9:08 ` Philippe Veber
2012-03-19 13:44 ` Edgar Friendly
2012-03-21 7:21 ` Philippe Veber
2012-03-16 17:23 ` Francois????Charles Matthieu????Berenger
2012-03-17 16:53 ` oliver
2012-03-19 9:08 ` Philippe Veber
2012-03-16 14:49 ` Jérémie Dimino
2012-03-18 21:11 ` Török Edwin [this message]
2012-03-19 9:11 ` Philippe Veber
2012-03-16 20:11 ` oliver
2012-03-18 23:56 ` oliver
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=4F664F7B.6020405@etorok.net \
--to=edwin+ml-ocaml@etorok.net \
--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