Array w/trig function passing through

This is a discussion on Array w/trig function passing through within the C++ Programming forums, part of the General Programming Boards category; As an example I have an array w/dimensions 8X8 The elements of this array contain objects with a char value ...

  1. #1
    Registered Abuser
    Join Date
    Sep 2007
    Location
    USA/NJ/TRENTON
    Posts
    127

    Array w/trig function passing through

    As an example I have an array w/dimensions 8X8

    The elements of this array contain objects with a char value and a hash-key value except for 8 of these 64 elements.

    I want these 8 elements to contain a different form of data, it also doesn't matter where in the array these 8 are located so they can be any:

    C(64,8)


    My question is is this implementable using an array or vector or do I need to design my own indexed structure to handle this task?

  2. #2
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    You want, what, a heterogenous array? That is, where some elements have a different data type than most?

    That's not doable using arrays or vectors. You'd need at least an array of some kind of discriminated union.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  3. #3
    Registered Abuser
    Join Date
    Sep 2007
    Location
    USA/NJ/TRENTON
    Posts
    127
    would it be bad to use an array and also an inheritance scheme on the data types so it could handle the two different types (there won't be more than two different types)?

  4. #4
    Registered User
    Join Date
    Oct 2007
    Posts
    66
    Couldn't you like make a few separate arrays for each datatype and then a masked array that tells you if an object is occupying any given point?
    "When your work speaks for itself - don't interrupt!"

    -Samantha Ingraham.

  5. #5
    Registered Abuser
    Join Date
    Sep 2007
    Location
    USA/NJ/TRENTON
    Posts
    127
    FULL PROBLEM:

    -chars are read from a file "atext.txt"

    -an initial key value is set (this defines the first sub-key of many depending on how large the text file is)

    -this key defines a trig function that occupies 8 elements of the array (always 8 no more no less)

    -envision graphing a trig function (or any fn for that matter) over a 2-D array (these 8 elements than have their own properties (they are not the same as the chars being read into the array from file)

    -the last value of these 8 defines the next fn of 8 elements in the next array

    -i want to take advantage of the indexing ability (and efficiency) of an array to accomplish this.

    -this is why i suggested perhaps an inheritance scheme

    like:
    Code:
    class entry{
    
    };
    
    class entryTypeOne : public entry{
    
    };
    
    class entryTypeTwo : public entry{
    
    };
    
    ...
    
    entry [8][8];
    or something of the such.

  6. #6
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    NO NO NO! Polymorphic arrays are BAD!

    Any efficiency you gain from an array, you lose when you introduce clever schemes to store different data types.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  7. #7
    Registered Abuser
    Join Date
    Sep 2007
    Location
    USA/NJ/TRENTON
    Posts
    127
    many thanks CornedBee, I think I've worked it out so I can use only one kind of object with this workaround:

    The 8 "key" elements are only chars anyway so they don't need to be different data types from what's being read from file.

    What is necessary is to know WHERE they are located within the 8X8 array.

    Basically my problem now is I need to use that last key-element to give me the 8 indices (of the next 8 key elements) in the next array (I guess a simple linked-list is the only feasable option here...)

    So I've gotta figure out how to use an unsigned char (0-255) to give me 8 indices from a possible permutation of P(64, 8) which is like

    64*63*62*61*60*59*58*57 possible ways of picking 8 (way to many hashing techniques for any practical means)

    Of course I really only need 256 of combinations but even that's pushing it, so that will have to be-rehashed (probably with a simple MOD technique)

    Any ideas?

  8. #8
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,308
    Wanting to do something one way doesn't mean its the best way. It looks to me like you're coding yourself into a corner by prematurely optimising.
    I suggest you just do the simplest thing that could possibly work and later optimise from there.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 05-13-2011, 08:28 AM
  2. Compiling sample DarkGDK Program
    By Phyxashun in forum Game Programming
    Replies: 6
    Last Post: 01-27-2009, 02:07 AM
  3. Replies: 7
    Last Post: 11-21-2008, 03:27 PM
  4. function passing argument..array ?
    By jochen in forum C Programming
    Replies: 2
    Last Post: 09-30-2007, 11:53 AM
  5. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 05:06 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21