Git Product home page Git Product logo

xorlist's Introduction

Xorlist

Double linked list with a single "next" field

The concept is simple as this:

The "key" field can be seen like the next AND the prev pointer of the node.

To get the address of the next item, you apply a xor bitwise operator of the previous item's pointer and its key:

A ^ B->key == C

So if you flip the operands, you can observe this statement:

C ^ B->key == A

You can see in the code that methods that can be used in both directions are greatly factorised, and can operate with a single pointer on the first or the last node. Since the previous pointer is always 'NULL', the orientation is totally transparent for the "go" methods which are called by "front" and "back" methods

Advantages:

  • You can observe a quite big difference for little programs which needs to list a lot of elements. (On the heap: 2,000 nodes will take 32,000 bytes instead of 48,000). The hardware costs are insignificant on today's computer, except on embedded systems!

Inconvenients:

  • You can't start from a node which isn't first or last.
  • You must keep the adress of the previous node to calculate the next pointer.

Variations exists with Addition key or Substraction key.

More informations about all that here: http://en.wikipedia.org/wiki/XOR_linked_list

If you are asking about strange developping decisions I made, just remember I coded this in optimizations purpose.

Cheers.

xorlist's People

Contributors

yartff avatar

Stargazers

 avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.