Coffeehouse Thread

4 posts

Forum Read Only

This forum has been made read only by the site admins. No new threads or comments can be added.

Idea #10: Messing With Fundamental Data Types

Back to Forum: Coffeehouse
  • User profile image
    billh

    I'm still working on this.  However, conceptually I am building a datatype such that:

    [ 0 ] [ 1 ] [ 2 ] [ 3 ] [ 4 ] [ 5 ] [ 6 ] [ 7 ] [ 8 ] [ 9 ] <-- indices (i); good for random access
    [ 1 ] [ 2 ] [ 3 ] [ 4 ] [ 5 ] [ 6 ] [ 7 ] [ 8 ] [ 9 ] [ 0 ] <-- travel layer (t); good for sequential access
    [ p ] [ p ] [ p ] [ p ] [ p ] [ p ] [ p ] [ p ] [ p ] [ p ] <-- pointers to actual objects (*p)

    To travel through container, you first would access a particular index, and then read the value in the t layer to get the value of the next index (destination, or which node to travel to next).

    For a singularly linked list (circular), the t layer in the above example would be:

    [ 1 ] [ 2 ] [ 3 ] [ 4 ] [ 5 ] [ 6 ] [ 7 ] [ 8 ] [ 9 ] [ 0 ]

    To flip it and reverse the list, replace the t layer with the following (probably via memset in C++):

    [ 9 ] [ 0 ] [ 1 ] [ 2 ] [ 3 ] [ 4 ] [ 5 ] [ 6 ] [ 7 ] [ 8 ]

    ...where these new "layer" values would already be defined when the type is first constructed.

    Grabbing the actual objects would be a matter of dereferencing the *p layer.

    Limitations: The obvious one is growth, or when objects are deleted/inserted. I suppose new objects could be tacked onto the end, but the trick is to find a way to do this without having to "resize".

    P.S. No, I do not need this for some job project.  This is just something I am going to mess around with on my own for the "fun" of it. Bigger ideas will follow soon. The more I look at this, though, the more it reminds me of an array full of pointers. Sad Yes, I know C++ has vectors.  Yes, I know it has linked lists, etc.

  • User profile image
    SlackmasterK

    billh wrote:

    No, I do not need this for some job project. 


    As long as you don't ask us to help you: "Write a function that would: 'return the 5th item from the end...'".

  • User profile image
    AndyC

    billh wrote:

     The more I look at this, though, the more it reminds me of an array full of pointers.



    That's exactly what I thought. It's possible you've re-invented the wheel. Only squarer. Wink

  • User profile image
    staceyw

    As I see it, the (t) layer does not add any value.  You can use the indices to do both.  The problem will always be resize.  To get perf, you need continuous memory block so you can add to the pointer to get the next location.  That is how arrays are laid out.  To reverse it, you don't even need to copy it, just use a reverse iterator.  Not sure what you going for here.  Could you expand.

Conversation locked

This conversation has been locked by the site admins. No new comments can be made.