https://github.com/daar/linkedlist
A linkedlist implementation for freepascal
https://github.com/daar/linkedlist
Last synced: 4 months ago
JSON representation
A linkedlist implementation for freepascal
- Host: GitHub
- URL: https://github.com/daar/linkedlist
- Owner: daar
- Created: 2025-09-10T07:19:15.000Z (9 months ago)
- Default Branch: main
- Last Pushed: 2025-09-10T20:25:12.000Z (9 months ago)
- Last Synced: 2025-09-11T00:12:27.162Z (9 months ago)
- Language: Pascal
- Size: 6.84 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# 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:
```pascal
type
pData = ^TData;
TData = record
next, prev: pData; // must match linkedlist expectations
msg: shortstring; // your custom data
end;
````
Allocate and add nodes:
```pascal
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](https://github.com/daar/nova), you can install directly:
```sh
nova install daar/linkedlist
```
Then include it in your project:
```pascal
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.