Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

APIs for linked list module. #463

Open
ChetanKarwa opened this issue Jul 14, 2021 · 2 comments
Open

APIs for linked list module. #463

ChetanKarwa opened this issue Jul 14, 2021 · 2 comments
Labels
API Discussion on a specific API for a proposal (exploratory) topic: container (Abstract) data structures and containers

Comments

@ChetanKarwa
Copy link

Description

I am currently working on the Linked List module for stdlib (under GSoC 2021).
This issue is somewhat an extension to an already existing issue #68.
This especially focuses on APIs for Linked List. This thread is to welcome ideas for APIs that can be implemented in the module and ideas for optimum implementation of the same.

For my project, I have implemented 3 types of lists:

  • A simple linked list
  • A list of list
  • A list of arrays

Based on some tests with random data set, we decided that out of all the 3 implementations "list of list" is better compared to the other 2.
So for the time being, I intend to implement all the APIs on the "list of list" model.

APIs that I intend to implement

  • insert: Insert an element at the specified index of the list
  • set/replace: Replaces an element at the given index
  • clear: Deletes the whole list (Without memory leaks)
  • Size: Returns the size of the list
  • reverse: Reverse the list
  • sort: Sort the items in the list (if homogenous, not sure)
  • Concat: Appends a list to another list
  • slice: Returns a Slice (a continuous part) of the list
  • splice: Removes a continuous part of the list

Already Implemented

  • Get: Returns the element stored at index.
  • pop: Removes an element from the end of the list.
  • remove: Removes an element present at given index
  • append: Append an element at the end of the list

My works (link).

@ChetanKarwa
Copy link
Author

APIs that I have already implemented are pretty straight forward but the others are a bit tricky.
For instance,
Insert API, there can be many possible implementations but for now, I have decided to use the following idea to implement the same.
There can be 2 possible scenarios when it comes to inserting an element:

  • The child list where we need to insert the element is not full (i.e. number of elements < MaxSize)
    - Directly insert the element.
  • The child list is already full.
    - Splits the child list into two adjacent child lists (split the list at the index where we need to insert the element)

This is just one way to get past it, other ideas that occurred to me:

  • Create a new adjacent child list that will hold just the last element of the current list.
  • Create a new adjacent child list that will hold the last 50% of the elements of the current list. (More time consuming to traverse to the middle of the list)

This is just some example, so for writing such APIs I wish for as many perspectives as I can receive from the community.
Thank you.

@arjenmarkus
Copy link
Member

arjenmarkus commented Jul 15, 2021 via email

@milancurcic milancurcic added the API Discussion on a specific API for a proposal (exploratory) label Jul 15, 2021
@awvwgk awvwgk added the topic: container (Abstract) data structures and containers label Jul 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API Discussion on a specific API for a proposal (exploratory) topic: container (Abstract) data structures and containers
Projects
None yet
Development

No branches or pull requests

4 participants