npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

fhf-linkedlist

v1.1.1

Published

The fhf-linkedlist library is a high-performance JavaScript implementation of a linked list, leveraging WebAssembly for efficient memory management and fast execution. It provides an easy-to-use API for common linked list operations such as appending, pus

Downloads

62

Readme

Overview

The fhf-linkedlist library provides a powerful and efficient implementation of a linked list using WebAssembly for performance-critical operations.

Table of Contents

  1. Installation
  2. Getting Started
  3. Class: LinkedList
  4. Memory Management
  5. WebAssembly Integration
  6. Examples

Installation

To install the fhf-linkedlist library, use npm:

npm install fhf-linkedlist

Getting Started

Here's a quick example to get you started with fhf-linkedlist:

import LinkedList from "fhf-linkedlist";
(async () => {
	const list = new LinkedList([1, 2, 3]);
	await list.append(4);
	await list.display(); // Outputs: 1 -> 2 -> 3 -> 4
})();

Class: LinkedList

Methods

append(data)

Adds a new element to the end of the list.

  • Parameters:

    • data: The data to append.
  • Usage:

    await list.append(5);

push(data)

Adds a new element to the beginning of the list.

  • Parameters:

    • data: The data to push.
  • Usage:

    await list.push(0);

display()

Displays the elements of the list.

  • Usage:

    await list.display();

length()

Returns the number of elements in the list.

  • Returns:

    • Number: The length of the list.
  • Usage:

    const len = await list.length();
    console.log(len); // Outputs: 4

reverse()

Reverses the list.

  • Usage:

    await list.reverse();

freeList()

Frees the memory allocated for the list.

  • Usage:

    await list.freeList();

get(index)

Gets the value at the specified index.

  • Parameters:

    • index: The index of the element to retrieve.
  • Returns:

    • Any: The value at the specified index.
  • Usage:

    const value = await list.get(2);
    console.log(value); // Outputs: 3

deleteNode(index)

Deletes the node at the specified index.

  • Parameters:

    • index: The index of the node to delete.
  • Usage:

    await list.deleteNode(1);

insert(index, data)

Inserts a new element at the specified index.

  • Parameters:

    • index: The index at which to insert the new element.
    • data: The data to insert.
  • Usage:

    await list.insert(1, 10);

sort()

Sorts the elements of the list.

  • Usage:

    await list.sort();

toArray()

Converts the linked list to an array.

  • Returns:

    • Array: The array representation of the linked list.
  • Usage:

    const array = await list.toArray();
    console.log(array); // Outputs: [6, 5]

Memory Management

The linked list utilizes WebAssembly memory for efficient allocation and manipulation. The memory is configured with an initial size and a maximum size to handle the linked list operations.

WebAssembly Integration

The library uses WebAssembly to perform core linked list operations such as appending, pushing, deleting, and reversing nodes. The main.wasm file is loaded and instantiated, providing access to the exported functions used within the LinkedList class.

Examples

Creating and Displaying a Linked List

import LinkedList from "fhf-linkedlist";

(async () => {
	const list = new LinkedList([1, 2, 3]);
	await list.display(); // Outputs: 1 -> 2 -> 3
	await list.freeList();
})();

Appending and Pushing Data

import LinkedList from "fhf-linkedlist";

(async () => {
	const list = new LinkedList([1, 2, 3]);
	await list.append(4);
	await list.push(0);
	await list.display(); // Outputs: 0 -> 1 -> 2 -> 3 -> 4
	await list.freeList();
})();

Reversing the List

import LinkedList from "fhf-linkedlist";

(async () => {
	const list = new LinkedList([1, 2, 3]);
	await list.reverse();
	await list.display(); // Outputs: 3 -> 2 -> 1
	await list.freeList();
})();

Getting Length of the List

import LinkedList from "fhf-linkedlist";

(async () => {
	const list = new LinkedList([9, 2, 10, 4, 5]);
	const length = await list.length();
	console.log(length);
	await list.freeList();
})();

Sorting the List

import LinkedList from "fhf-linkedlist";

(async () => {
	const list = new LinkedList([3, 1, 4, 1, 5]);
	await list.sort();
	await list.display(); // Outputs: 1 -> 1 -> 3 -> 4 -> 5
	await list.freeList();
})();

Turning the List into an Array

import LinkedList from "fhf-linkedlist";

(async () => {
	const list = new LinkedList();
	await list.push(5);
	await list.push(6);
	console.log(await list.toArray()); // Outputs: [6, 5]
	await list.freeList();
})();

Freeing the List

import LinkedList from "fhf-linkedlist";

(async () => {
	const list = new LinkedList([1, 2, 3, 4, 5]);
	await list.freeList();
	await list.display(); // Outputs nothing, as the list is now empty
})();

Conclusion

The fhf-linkedlist library offers a high-performance linked list implementation with the power of WebAssembly. This documentation provides a comprehensive guide to using the library, focusing on the index.js file. For further assistance, refer to the additional examples and method descriptions provided.