Skip to content

Latest commit

 

History

History
 
 

libmba

libmba

C sources from the libmba library by Michael B. Allen (MIT License).


Table of Contents


Folder Contents

About Libmba

Libmba is a library of generic C modules, created by Michael B. Allen. From the libmba home page:

The libmba package is a collection of mostly independent C modules potentially useful to any project. There are the usual ADTs including a linkedlist, hashmap, pool, stack, and varray, a flexible memory allocator, CSV parser, path canonicalization routine, I18N text abstraction, configuration file module, portable semaphores, condition variables and more. The code is designed so that individual modules can be integrated into existing codebases rather than requiring the user to commit to the entire library. The code has no typedefs, few comments, and extensive man pages and HTML documentation.

The files in this directory tree were taken from libmba v0.9.1 (Apr 29, 2005).

File Changes and Notes

The allocator.c module was tweaked to solve memory management problems under Windows.

The suba.c differs slightly from the upstream version in a couple of places (LL 293–295, 326).

The cfg.c module fails to compile on OS X, and was excluded from the project.

Project Usage

The project only requires the diff.c module and its dependencies from libmba:

which are compiled to a static library (libmba.lib/libmba.a). The other libmba modules are not used by this project.

The PureBasic IDE uses the diff algorithm from libmba to track file changes for the session history in ../EditHistory.pb (LL 58–72):

;- Libmba stuff
;
CompilerIf #CompileWindows
  ImportC #BUILD_DIRECTORY + "libmba/libmba.lib"
  CompilerElse
    ImportC #BUILD_DIRECTORY + "libmba/libmba.a"
    CompilerEndIf

    diff.l(*a, aoff.l, n.l, *b, boff.l, m.l, *idx_fn, *cmp_fn, *context, dmax.l, *ses, *sn.LONG, *buf)

    varray_new(membsize, *al)
    varray_del.l(*va)
    varray_get(*va, idx)

  EndImport

The Libmba Diff Algorithm

From the libmba API Reference of the diff module:

The diff(3m) module will compute the shortest edit script (SES) of two sequences. This algorithm is perhaps best known as the one used in GNU diff(1) although GNU diff employs additional optimizations specific to line oriented input such as source code files whereas this implementation is more generic. Formally, this implementation of the SES solution uses the dynamic programming algorithm described by Myers [1] with the Hirschberg linear space refinement. The objective is to compute the minimum set of edit operations necessary to transform a sequence A of length N into B of length M. This can be performed in O(N+M*D^2) expected time where D is the edit distance (number of elements deleted and inserted to transform A into B). Thus the algorithm is particularly fast and uses less space if the difference between sequences is small. The interface is generic such that sequences can be anything that can be indexed and compared with user supplied functions including arrays of structures, linked lists, arrays of pointers to strings in a file, etc.

[1] E. Myers, "An O(ND) Difference Algorithm and Its Variations," Algorithmica 1, 2 (1986), 251-266.

The full article by Eugene Myers is available at this URL:

For an in-depth explanation of Myers' diff algorithm, see Nicholas Butler's two-parts tutorial and his free visual tool for tracking the algorithm step by step:

License

The libmba library is Copyright © by Michael B. Allen, released under the terms of the MIT License.

The MIT License

Copyright (c) 2001-2005 Michael B. Allen <mba2000 ioplex.com>

Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.