Skip to content

daar/linkedlist

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

linkedlist

A simple doubly linked list implementation for FreePascal.
This code was originally taken from Blender 1.72 and later ported by Darius Blaszyk.
It provides basic list operations such as adding, removing, inserting, and freeing nodes.

Features

  • Doubly linked list structure (next and prev pointers).
  • Basic memory management (malloc, calloc, free).
  • Core list operations:
    • Add to head (addhead) or tail (addtail)
    • Remove a node (remlink)
    • Insert before/after a given node (insertlink, insertlinkbefore)
    • Count nodes (countlist)
    • Free a single link (freelinkN)
    • Free the entire list (freelist)

Usage

Define your own record type with next and prev fields as the first two members, for compatibility with the linked list API:

type
  pData = ^TData;
  TData = record
    next, prev: pData;     // must match linkedlist expectations
    msg: shortstring;      // your custom data
  end;

Allocate and add nodes:

var
  list: ListBase;
  node: pData;
begin
  list.first := nil;
  list.last := nil;

  node := calloc(1, sizeof(TData));
  node^.msg := 'Hello, world!';
  addtail(@list, node);

  writeln(countlist(@list)); // prints 1

  freelist(@list); // cleanup
end;

Installation

With Nova package manager

If you are using Nova, you can install directly:

nova install daar/linkedlist

Then include it in your project:

uses
  linkedlist;

License

This code is dual-licensed under the GNU GPL v2 or later and the Blender License 1.0. See the file header for details.

About

A linkedlist implementation for freepascal

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages