Next: , Previous: , Up: Parsing procedures   [Contents][Index]


2.3.2 Parsing string tables

The ‘(parser elf cstrings)’ module exports ‘parse-cstring-bstree’ and ‘search-cstring-bstree’ for the purpose of efficiently dealing with string tables.

Here is an example:

;; ASCII for \0 A A A \0 B B B \0 C C C \0
(define bv #vu8(0 65 65 65 0 66 66 66 0 67 67 67 0))
(define bstree (parse-cstring-bstree bv 0 (bytevector-length bv)))
(search-cstring-bstree bstree 0)
  ⇒ ""
(search-cstring-bstree bstree 1)
  ⇒ "AAA"
(search-cstring-bstree bstree 6)
  ⇒ "BB"

Example 2.2: Parsing a string table into a binary search tree and indexing it.

Procedure: parse-cstring-bstree bv start end

Parse a balanced binary search tree out of the bytevector bv of C strings from start to end. The returned object is opaque and is meant to be used with serach-cstring-bstree. The strings are assumed to be latin-1 encoded.

Procedure: search-cstring-bstree bstree index

Indexes the string table represented by bstree at index.