mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

Interesting comments! Let me rebute a few things.

Is really funny how many Linux users bash over Windows, and Windows users don't bash over Linux

Maybe it can be explained this way. Some people (I would argue, most) start to use Linux and have such a nice experience with it that they feel very strongly in favor of it, almost stop using Windows, and see nothing but problems whenever they use Windows again. While most Windows users never tried Linux, and those that did without ending up switching permanently, feel the way you expressed it, they find Linux nice in many ways, with a few usability problems and still prefer Windows, but they respect Linux.

ohh and let me explain the myth that Linux is virus free and that windows is flawed by it's design, the true is clearly visible and only fanboys and\or blind people can't admit it the truth, "Windows is the Main Target all over the World"

Obviously, that's a major factor for personal computer viruses and malware. But serious hackers attack servers, and they spend a lot of energy trying to crack them open, and the vast majority of the servers are Linux / Unix / Solaris whose system architectures are the all same for all practical purposes. The truth is, a Windows server can barely stay up a month or two without being cracked open, while Linux servers can stand strong for years (and that's not an exageration) as long as …

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

"In computer programming, clever and simple are synonyms." - your humble moderator

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

For the samba problem, just run a search like this:

$ aptitude search samba

and it will print the list of packages with the name "samba" in it. You can just install all the packages that are relevant from that list. If a package appears in the list, then you should be able to install it. If no useful packages appear in the listing, then your problem must be with the repositories that are not setup correctly.

As for the ssh problem, in order to be able to connect to a server via ssh, the server must be listening for ssh connections. Normally, if you have installed ssh (either ssh or openssh-client openssh-server), then the ssh server should be running upon startup of the computer, and it will be able to accept incoming connections.

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

The library should be part of "glibc" package, which is a fundamental system package, I doubt that you lack it.

To find the ld-linux.so.2 try to run this command:

$ locate ld-linux

It is possible that the file in question appears in the wrong directory, like /lib64 or something. You can then make a symlink to that file in the /lib folder.

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

The way I see it, every programmer has a bag of tricks that they use. To me, the point of the contest is to show off one such trick that you think is clever and/or useful. It can be a nice language-technical trick (e.g., doing something that people don't suspect can be done), a nice algorithmic trick (e.g., a clever tail-recursion, or something), or a very useful little tool (e.g., a kind of smart-pointer). When you program a library or large application, most of the code is boringly ordinary, but once in a while you come up with a very neat solution to a particular problem / application. The idea is to take one such trick (or come up with one) and formulate it in a self-contained snippet (like the class that implements the solution, and a basic program that demonstrates it use / purpose). Then, it will be part of the code-snippet library, and people that read it might think its just cool or a very nice way to solve a type of problem.

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

I just filled it. I hope you get a lot of people to fill it too, I will be interesting to see the results.

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

What about the issue with leading spaces in the code blocks?

// This is why this problem annoying:
void some_function(int param1,
                                      int aligned_param2,
                                      int aligned_param3);

The spaces in the editor (only the ones at the beginning of the line) seem to be half the width they should be. (see attachement)

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

The two rational numbers, r1 and r2, should be declared outside of the loop if you want them to keep on storing the last values entered (just like you used to have those ratNum1, ratNum2.. variables before). So, if you move the declaration, Rational r1, r2; to where the "option" variable is declared, all should work fine.

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

It does not occur on Chrome.

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

Does everything have to be in one file and in one language?

In my opinion, it should just be in one language, unless the other-language-code is a very common external library. But, it's Dani's call.

And it can certainly be in multiple files, but I would try to keep it within reason.

When was the last time you coded anything cool all in one file?

Well, one of the coolest piece of C++ code is the ScopeGuard, and it fits in about 30 lines of code.

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

@rubberman:
LOL!
I guess it takes an experience software engineer like you to make such a necessary addition. How many times does the word "bonehead" appear in your 10M lines of 6-sigma production code? I guess with 1 chance in a million to fail, you can write anything you like in the error messages.

Btw, the original message-box text was from the OP, not me.

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

Welcome!
Then prepare a good piece of code, post it to the relevant sub-forum (as a code-snippet), and post a link to that code snippet on this thread (to make it "official").

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

I can confirm that the cursor problem is fixed.

However, the space size problem is not fixed.

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

You can indent by hitting tab. What's easier than that?

I can indent the entire code with tab, but that's not the point, see the snapshot.

And, yes, it occurs in all editors.

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

Also, what OS and browser are you using, and what browser version.

My OS is Kubuntu 11.10:

Linux MPdesktop 3.0.0-20-generic #34-Ubuntu SMP Tue May 1 17:24:39 UTC 2012 x86_64 x86_64 x86_64 GNU/Linux

And my browser is Google Chrome version 19.0.1084.56-r140965:

Google Chrome   19.0.1084.56 (Official Build 140965)
OS  Linux
WebKit  536.5 (@119244)
JavaScript  V8 3.9.24.29
Flash   11.2 r202
User Agent  Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/536.5 (KHTML, like Gecko) Chrome/19.0.1084.56 Safari/536.5
Command Line     /opt/google/chrome/google-chrome --flag-switches-begin --flag-switches-end
Executable Path /opt/google/chrome/google-chrome
Profile Path    /home/mikael/.config/google-chrome/Default
mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

Ok, I took the screenshots that you wanted.

And, I'm not sure that it has been a week, it could be only a few days.

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

Ok, so I assume you have something like this:

ClientNode* getMatchingClient(const ClientInfo& aClient) const {
  ClientNode* current_node = head;
  while( current_node != NULL ) {
    //.. ?
    current_node = current_node->next;
  };
  return NULL;
};

To check for the match, you have to access the data member of the current node and call the isMatching function on it. As so:

ClientNode* getMatchingClient(const ClientInfo& aClient) const {
  ClientNode* current_node = head;
  while( current_node != NULL ) {
    if( current_node->data.isMatching( aClient ) )
      return current_node;
    current_node = current_node->next;
  };
  return NULL;
};

It's that simple.

Have you implemented the addClient function and destructor? You might want to post that code, because it can be tricky, and I want to make sure it is right.

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

Yes. Now you can extract the information the same as with cin, but with ss instead.

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

Just to add more description. The same thing happens with inline-code.

I'm pretty sure this behavior is due to the fact that the code (inline or not) font in the highlighting is one pixel taller than the font on the normal text. And the cursor position seems to be calculated from the current_line_number * font_height_of_normal_text. That explains it, but doesn't solve it. I think you just need a more reliable method to get the vertical position where the cursor should appear. Or, you could just make sure that all the special fonts (code, links, bold, etc.) are all the same height as the normal font.

Also, about the fixed-width font for code. It appears that it is only a problem with the spaces at the start of the line (indentation!) that aren't the same width as the rest of the code letters. We keep talking about how important indentation is, it would helpful to have an editor that allows us to correctly indent easily.

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

You can assume, for all practical matter, that the std::vector class just stores two fields: the size of the array and a pointer to the first element of the array. In other words, this is the same as what you would have to do if you allocated the dynamic array yourself with new[]. When you have a fresh vector (empty), the internal pointer is most likely set to NULL. You can also assume that the iterator type std::vector<int>::iterator is the same as int* (e.g., a pointer). So, when you call begin(), it will, in effect, just give you the pointer to the start of the array (the pointer that the vector stores internally). So, on a fresh and empty vector, that pointer is NULL (and so will be the iterator at begin()), and dereferencing it is going to cause a crash (access violation, segmentation fault). This explains the crash if you have both lines 21 and 23 commented out.

If you have resized the vector, then the internal pointer is no-longer NULL, which explains the non-crash behavior when using line 21 or 23. If you allocate space for 1 value, but end up writing 3 elements (via an iterator), you will be writing beyond the memory that was allocated (or allowed), this may or may not result in a crash, but in either case, it is bad. The reason why you get (1,0,0) after you resize the vector is because resizing from 1 to 3 adds two elements which are …

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

how do you use the std::stringstream function?

The stringstream class is a way to transform a string into a stream (a stream is what the cout and cin are). Here is a working example:

#include <iostream>
#include <string>
#include <sstream>   // this is the header for the stringstream.

using namespace std;

int main() {
  // Say I create this string:
  string some_string = "This is a sentence with words in it.";

  // Then, I can create a stringstream from that string, as so:
  stringstream ss(some_string);

  // Then, I can use this strinstream object as I would with cin:
  cout << "Individual words in '" << some_string << "' are:" << endl;
  string one_word;
  while( ss >> one_word ) {  // read words until none are left.
    cout << one_word << endl;
  };

  // you can also use this to extract numbers from a string:
  string some_num_str = "3 4 87 32 90 23 42";

  stringstream ss2(some_num_str);
  cout << "Individual numbers in '" << some_num_str << "' are:" << endl;
  int one_num;
  while( ss2 >> one_num ) {
    cout << one_num << endl;
  };

  return 0;
};

The above program should output each separate word on a line, and then each separate integer on a line. The stringstream class is the way that you can extract various words or numbers from a string, with the same logic as you would use to capture words or numbers from cin. The stringstream class also works in reverse, i.e., you …

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

Hi,

I've been experiencing a weird bug in the editor (for a week or so). If I write a post, everything is fine and dandy until I start a block of code. From the first line of code that I write, and for every subsequent line of code after that, the cursor (the blinking line) gets offset by one pixel upwards. By the time I've written like 10-20 lines of code, the blinking line sits a full line above the place where I'm writing. The behavior continues after the code block is done (when writing normal text again), but the offset stops getting worse. The same offset applies to selecting some text that appears after the code.

This is quite annoying. I can always write the longer posts from a text-editor on the side and copy-paste the text back again, but I shouldn't have to do that.

Also, the blocks of code no longer appear in fixed-width font (when highlighted in the editor) like it used to. Writing code without a fixed-width font is very annoying.

FYI, I'm using Google Chrome, running under Linux (Kubuntu 11.10).

Anyone else experiencing the same problem? Dani, any ideas what the problem is? Solution?

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

There was a bit of a problem here because I wrote my last post at the exact same time as you wrote your last post. So, I didn't see your last post (with the ClientInfo class) before now.

First, the data like name, phone-number, and interests should be stored as std::string (from header <string>), not as the char-arrays that you have. And, as for the "interests", the problem says that there should be many interests recorded for each client, so, you will need to have an array of interests, as well as a count of the number of interests recorded for one client. The best way to record that list of interests is through a C++ class called std::vector, however, I'm afraid you might not be allowed to use it (because these classes (called STL containers) are often not allowed in basic programming assignments, although, in real-life, you'd use them everywhere you can). So, instead, you can use a limited array of interests (e.g., maximum of 10 interests per client). With that in mind, you would get these private data members:

class ClientInfo
{
  private:
    char sex;
    std::string name;
    std::string phoneNum;
    int numberOfInterests;
    std::string interests[10];  // maximum of 10 interests can be listed. 
    std::string match;     // I guess this is the name of the matching client.

  public:

    // ...

};

The "linked-list" data-members and functions that you have in your ClientInfo class should not appear there, they don't belong there. The ClientInfo class only …

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

I find that Python is a really nice language to learn in addition to C++, because it is very different (very high-level), easy, and it works very well along-side C++ (Python is often used as a high-level scripting language to use to run C++ code, through python-bindings).

I read everywhere that programmers should know several languages, but tell me, aren't you confusing them all the time when coding once in one language, and then in another ?

I happen to speak four languages at functional to fluent level (English, French, Swedish and German), and I have basics skills in a few others (Spanish, Italian, Finnish, and Dutch). I usually don't confuse them when I speak or write. But, for example, when I go to Sweden, it takes me a week or two to get used to speaking Swedish on a daily basis (which I don't use here, in Canada), in that time, my skills and knowledge of the language move from latent (passive) to active. Also, knowing many languages gives rise to a few quirks, like using words from one language when speaking another, or being frustrated once in a while to not be able to express something in one language as well as you could in another (e.g., I always swear in canadian-french, because it expresses it better). Then, there are subtle influences, for example, because french is my native language, when speaking english I tend to use more words and expression of french ethymology, and my …

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

Well, I happen to have written a tutorial on how to write a class like that. Read it here.

Your class is no different than the standard std::vector class (except that the standard class has way more features). So, I recommend you use that instead.

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

Sorry about the "r" thing, it's a typo, it should be "rat" (i.e., the function parameter!). As in:

//output operator, to print a Rational number:
ostream& operator << (ostream& out, const Rational& rat) {
  out << rat.getNumerator();
  if(rat.getDenominator() != 1) // print denominator only if it is not 1.
    out << "/" << rat.getDenominator();
  return out; // don't forget to return the ostream object.
};
//input operator, to input a Rational number from a stream:
istream& operator >> (istream& in, Rational& rat) { // notice the & here.
  int num = 0, den = 1;
  in >> num;
  if(in.peek() == '/') { //check if there is a denominator.
    char temp;
    in >> temp >> den; // read the denominator.
  };
  rat.setNumerator(num);
  rat.setDenominator(den);
  return in; // don't forget to return the istream object.
};
alsz commented: Hey Mike, No need to apologize man, I should have figured it out myself. I really appreciate the help and thank you so much for all the help and hints. Have an awesome day!! Sincerely, alsz +0
mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

The two functions that I posted (input and output) should be free functions (not members of the Rational class). You can simply insert them after the class declaration and before the main() function. Or, you can put them after the main function, but then, you have to insert the declarations between the Rational class declaration and the main function, as so:

class Rational {
  //.. 
};

ostream& operator << (ostream& out, const Rational& rat);  // declaration.
istream& operator >> (istream& in, Rational& rat);         // declaration.

int main() { 
   //... ...
};

// then, somewhere here, insert the code I gave, verbatim.

The error message you got is because those functions should not be member functions of the Rational class, they must be free functions (outside the class, so, no Rational:: should appear).

And, remember to make the two get-functions const as I said earlier. Otherwise, you'll get an error like this:

error: passing ‘const Rational’ as ‘this’ argument of ‘int Rational::getNumerator()’ discards qualifiers [-fpermissive]
mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

What about a while loop? Something like this:

  boolean shouldContinue = true;
  while(shouldContinue) {
    shouldContinue = false;
    input = JOptionPane.showInputDialog("Enter a number between 1 and 10 " +
                   "and I will convert it to a Roman numeral: ");
    num = Integer.parseInt(input);
    if (num == 1)
       JOptionPane.showMessageDialog(null, "I");
    else if (num == 2)
       JOptionPane.showMessageDialog(null, "II");
    else if (num == 3)
       JOptionPane.showMessageDialog(null, "III");
    else if (num == 4)
       JOptionPane.showMessageDialog(null, "IV");
    else if (num == 5)
      JOptionPane.showMessageDialog(null, "V");
    else if (num == 6)
      JOptionPane.showMessageDialog(null, "VI");
    else if (num == 7)
      JOptionPane.showMessageDialog(null, "VII");
    else if (num == 8)
      JOptionPane.showMessageDialog(null, "VIII");
    else if (num == 9)
      JOptionPane.showMessageDialog(null, "IX");
    else if (num == 10)
      JOptionPane.showMessageDialog(null, "X");
    else {          //error message   
      JOptionPane.showMessageDialog(null, "Not good at following instructions?" +
                                            "\nI said enter a number between 1 and 10!");
      if( JOptionPane.showConfirmDialog(null,
                 "Do you want to try again?",
                 "Try again?", JOptionPane.YES_NO_OPTION) 
                  == JOptionPane.YES_OPTION )
        shouldContinue = true;
    };
  };
  System.exit(0);

Or, you can do it slightly differently if you want to allow retries even if the person entered a good number. You get the basic idea here: use a while-loop and set the flag depending on what happened in the loop, to trigger a repeat or not.

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

now do you mean i just make a class to store the information?

I remember saying something like that....
"Start by writing a class to store the information related to one client."

how does the linked list come into play?

I'm just trying to get you to solve this problem step by step, to make sure you solve the problems as they come. So, once you have the class to store the info, and the functions to get the info from the user and print it out again, and that you have tested that. Then, you have to start working on the linked-list, because that's what the assignment asks for.

instead of an integer would i use a char to represent each node?

What integer? Why a char instead? This makes no sense to me. Once you have a class for the client-info, your linked-list will just have to store objects of that class. So, the nodes would be something like this:

struct ClientNode {
  ClientInfo client_data;
  ClientNode* next;
};

where ClientInfo would be the class that you have created to store the client information.

Your linked-list class would store a pointer to the ClientNode that sits at the head of the list, and each node's next pointer points to the next node in the list. And the final node would have a NULL next pointer.

But, as I said, start by writing the ClientInfo class and its functions. And proceed …

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

Did it occur to you that you can test this out very easily? When it comes to performance, the only thing that can settle the argument is test results, the rest is just speculative non-sense. Try this:

#include <iostream>
#include <ctime>
#include <algorithm>
#include <cstring>
#include <iomanip>

union Record {
  struct {
    double x,y,z;
  };
  struct {
    double Magnitude, Direction, Angle;
  };
};

using namespace std;

int main() {

  const int X = 10000;
  const int Y = 10000;

  Record* p_records = new Record[X * Y];

  int k = 0;
  clock_t t_start = clock();
  for(int i = 0; i < X; ++i) {
    for(int j = 0; j < Y; ++j) {
      p_records[k].x = 0;
      p_records[k].y = 0;
      p_records[k].z = 0;
      ++k;
    };
  };
  clock_t t_end = clock();
  cout << "First method took: \t" << setw(10) << (t_end - t_start) << " clocks." << endl;

  t_start = clock();
  for(int i = 0; i < X * Y; ++i) {
    p_records[i].x = 0;
    p_records[i].y = 0;
    p_records[i].z = 0;
  };
  t_end = clock();
  cout << "Second method took: \t" << setw(10) << (t_end - t_start) << " clocks." << endl;

  t_start = clock();
  Record* end_records = p_records + X * Y;
  for(Record* p = p_records; p != end_records; ++p) {
    p->x = 0;
    p->y = 0;
    p->z = 0;
  };
  t_end = clock();
  cout << "Third method took: \t" << setw(10) << (t_end - t_start) << " clocks." << endl;

  t_start = clock();
  Record zero_rec;
  zero_rec.x = 0;
  zero_rec.y = …
mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

Start by writing a class to store the information related to one client.

Then, write a function to obtain the information from the user and write it into a client record.

Then, write a function to print out the information in a client record.

And, then you can start working on the linked-list structure.

I can't give you more details on that because our policy here is not to just give code to people. You have to work on this yourself and ask questions about specific problems you have along the way. That's the only way to learn.

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

I ran your code and I get exactly what is expected. That is, I called $ ./clone_test 2 and I got this output:

PID =  27719 
PPID = 27718 
PID(child of a child) =  27720 
PPID(child of a child) = 27719 
PID =  27721 
PPID = 27718 
PID(child of a child) =  27722 
PPID(child of a child) = 27721 
PID(child of a child) =  27723 
PPID(child of a child) = 27721

Which means that the original process (PID 27718) spawns the child processes 27719 and 27721. And the child process 27719 spawns one child process 27720. And the second child process 27721 spawns two children, 27722 and 27723.

If I understood right, this is exactly the behavior you want, right? Can you clarify what the problem is?

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

Pass it by const-reference, as so:

BoxArray& Delete(const Box& BoxToDelete, bool All = false);

That will bound to a temporary too (formally called an "rvalue").

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

This is a great start! You have clearly put some effort into it.

The easiest way to solve this problem with the inputs of the rational numbers is to create a separate function for inputting and outputting a rational number. And the best way to do this is to overload the << and >> operators for the iostreams. By simply taking your code and putting it into the following functions:

//output operator, to print a Rational number:
ostream& operator << (ostream& out, const Rational& rat) {
  out << r.getNumerator();
  if(r.getDenominator() != 1)  // print denominator only if it is not 1.
    out << "/" << r.getDenominator();
  return out; // don't forget to return the ostream object.
};

//input operator, to input a Rational number from a stream:
istream& operator >> (istream& in, Rational& rat) {   // notice the & here.
  int num = 0, den = 1;
  in >> num;
  if(in.peek() == '/') {  //check if there is a denominator.
    char temp;
    in >> temp >> den; // read the denominator.
  };
  r.setNumerator(num);
  r.setDenominator(den);
  return in; // don't forget to return the istream object.
};

Notice that I used pass-by-reference in the above. In the first case, I pass a const-reference, which means that the variable (within the function) refers directly to the variable on which it was called, but without permission to change it. In the second case (input), I pass by reference (non-const), which means that there is permission to change the variable, and because it …

alsz commented: @Mike O_o I am so sorry , but how do you exactly implement the first part of your solution into my code or my code into your solution. I have never seen the istream and ostream. Do I have to declare them in the class ? +0
mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

The general rule is this:

  1. Prefer declaring / defining your operator overloads as non-member functions;
  2. If you need access to private members, make them non-member friend functions;
  3. If that particular type of operator must be a member function (like the assignment operator, or conversion operators), then make it a member function.

As for the difference between parameters as (Box B1) and (const Box& B1), well, that is just the difference between pass-by-value and pass-by-reference. Generally, for any non-primitive type (like a class), use the pass-by-reference, e.g., (const Box& B1).

As for your actual error (undefined reference), this is because you declared the operators are inline. When you declare a function as inline, its definition (implementation) must appear in the header file. So, to fix the problem, either you remove the inline keywords from the declarations, or you move the definitions to the header file (e.g., after the class declaration). Either way is fine. If the function is a simple one-liner function, then it might as well be inline and put in the header file, but for longer functions, there is no point in making them inline.

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

That's true only at the base of the tree. If you're jumping from index i to 2 * i + 1, for any large i, you won't get prefetching performance from that reason.

You're right. At least, under simplified models. Pre-fetching, coupled with branch-prediction, has gotten a lot better and more complex over the last decade, making their performance very hard to predict without relying heavily on empirical evidence.

Also, here's another pre-fetching scenario that is not completely unrealistic IMHO. Say you are looking at two (or d) sibling nodes, branch-prediction is likely to figure out that you will be jumping to one of the children groups next (to look at the children of one sibling or the other), and because they are next to each other, the entire group of four (or d^2) nodes can be pre-fetched before knowing which pair you will want to look at next. And that mechanism works anywhere in the tree (because direct "cousins" will always be packed together). So, one block can be pre-fetched, and it will accomodate any branch that you will want to follow after the search conditions (e.g., node comparison) has been evaluated, without ever doing a pre-fetch mistake (unless you quit the traversal early), or having to wait for the condition. I'm not sure how good and sophisticated these pre-fetching with branch-predictions occur. But one thing is for sure, anything beats the linked-list-style storage, because you'll never be able to get such a consistent one-pre-fetch-for-all-branches behavior, regardless …

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

I'm really sorry about all the confusion about the terms. I just realized, after my previous post, that the B-tree term also refers to this specific type of search tree. In the literature I have been reading, they used B-tree as a short for "Breadth-first layout (or tree)". As for BST, I thought it was a general term (umbrella term) for all binary search tree algorithms (in the same way as binary space partitioning (BSP) is an umbrella term for all sorts of different space partitioning techniques). I guess by trying to avoid talking about irrelevant details, I caused all sorts of confusion about what I was talking about.

To make it clear, the basic idea of a breadth-first layout is this. Say you have a binary tree, with node A as root, (B1,B2) as children, and (C1,C2) as children of B1 and (D1,D2) as children of B2. Then, you layout the nodes in a contiguous array as so: (A, B1, B2, C1, C2, D1, D2). This has the effect that if you do a breadth-first traversal of the tree, it is the same as doing a linear traversal of the array (hence, the name "breadth-first layout"). When you do a depth-first traversal or a searching for a particular key, the memory access pattern is also pretty efficient because it always goes forward in the array (as opposed to randomly jumping back and forth, which is what happens if you have a linked-list-style storage). And such access patterns are very …

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

The number of pixels to allocate is width * height. You shouldn't have the BytesPerPixel in there. It should be:

Pixels = new RGB[width * height];

As for the crash, it might have something to do with the fact that your array, that TEMP points to, is too small for the image size in bytes. Because of the padding at the end of the rows, the total size in bytes of the image is not equal to width * height * BytesPerPixel, it is slightly bigger than that. You should use the value stored in Info.bmiHeader.biSizeImage as the number of unsigned char to allocate. As in:

unsigned char* TEMP = new unsigned char[Info.bmiHeader.biSizeImage];

And use the same size value in the memset().

Finally, don't forget to close the file handle at the end of the function (you do it in all the if-statements, but you forgot to do it at the "normal" end).

Other than that, I'm not sure what could be causing the crash.

triumphost commented: Solved all my problems :) +0
mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

You can also try to download the package separately and manually swap it. You can download the package from here.

If the problem persists after you have checked the MD5 checksum, then you should report it to ubuntu bug-tracking.

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

@LastMitch:

Sometime in real life there’s consequence if things are not said in a correct matter.

Oh.. the irony is delightful.

I mean in person if you work for me I will fired

I'd quit before you have time to fire me. That is, if you could afford me in the first place.

You should wake up and smell what you're shoveling, and who you're throwing it at. I don't have to take this.

BTW, if you took more than 1 minute to write your posts, you might manage to put one coherent sentence together. And not ruin a perfectly nice thread in which people are discussing various ideas (whether you like them or not, or whether Dani is gonna use them or not). Learn to communicate your point of view clearly, coherently, and without pissing over everybody else.

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

You've been busy! Pretty nice code you have there.

There is one important mistake for sure, you allocate your pixel array as Pixels = new RGB[size]; where size is the size in bytes of the image. So, you need to allocate the pixels as Pixels = new RGB[width * height];.

The second error is to make the assumption that (sizeof(unsigned) == 4) that may not be the case on some computers. If you want a fixed and known size, you need to use the header <stdint.h> (or <cstdint> if you have a recent-enough compiler), and use the type uint32_t in your union:

typedef union RGB
{
    uint32_t Color;
    struct
    {
        unsigned char B, G, R, A;
    };
} *PRGB;

Another bone I have to pick is with the throwing of a string literal. You shouldn't do that. Prefer to throw an exception object. The standard provides a few useful ones, or you can make your own classes derived from the std::exception class.

Now, to the point of your questions.

The bitmap format (uncompressed, at 24 or 32 bpp) stores the colors as Blue-Green-Red(-Alpha) in little-endian byte-order (i.e. the Blue byte is the least-significant and stored first). So, that is exactly how you should read the pixels from the file. And that is not what you are doing at all. And, you do have to consider the padding at the end of the rows (to make it an even multiple of 4 bytes). You cannot read the …

triumphost commented: Best reply and most helpful person. +5
mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

Do you tend to find your answers from Google on other communities or message boards, by any chance? :)

It depends. For language-technical problems (e.g., "what is the linkage specification of a friend function of a class template?"), I tend to find answers on reference sites, in particular for C++, cplusplus.com, cppreference.com, msdn, IBM reference pages, etc. Once in a while, I find a helpful SO thread, or other C++ specific message boards. Very often, I look for answers on topics that I'm less familiar with (e.g., other prog. languages, reference information on external libraries, build system scripts, LaTeX commands, and so on), and then I do end up more often on specific message boards and on the reference wikis of the specific library or tool. Sometimes, (but rarely, I'm afraid to say,) I do end up on a Daniweb thread that answers the question. And then, the third kind of technical google searches that I might do are more on a theoretical level (algorithms, data structures, design patterns, etc.. CS stuff), in which case, the only sources for good answers are articles from peer-reviewed journals and conference proceedings, it is extremely rare to find answers to these questions on forums or message boards, and it is hard to trust or use any non-peer-reviewed stuff (if I find a good website talking about the given problem, I usually skim over to the end to follow the references cited, and if none appear, I move on, unless the site …

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

I agree that having a members-helping-members community is hard for the reasons deceptikon mentioned. If I have a language-technical problem, I first refer to the language's standard specification document. If that doesn't solve it, I google for it, using the proper terminology, and I usually find my answer pretty quickly, and that's the end of it. If I have a design or algorithmic problem, I refer to CS literature and usually find good ideas to work with.

But it's funny that you mention this problem of senior members not asking enough thought-provoking questions, because I just did, resulting in a nice discussion so far, see this thread.

I also agree with deceptikon about "advanced tangents" (and we've had a few of those). These are nice discussions, but the format of Daniweb sometimes makes you (the expert) feel guilty about taking over a beginner's thread with a discussion / debate about an advanced topic that probably doesn't concern the OP at all (or at least, not yet). Maybe there could be a way to specifically allow for advanced tangents without monopolizing the thread, like a forking of the thread or something like that.

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

The point is that small lists should be flattened, large ones will need to use another contiguous chunk of the heap.

I beg to differ. The point is not so much about size, but about the uniformity of the sizes. If you have a tree like a binary search tree, then the number of out-going edges is not only predictable but fixed (except for leafs). If you have a general graph you could have wild variations in the number of in-going or out-going edges. Now, if you want to flatten them, you need limited the edges to a fixed maximum number. If the max is large with respect to the average adj-list size, then you will be able to accomodate the more extreme scenarios (many edges on one node), but you will also waste a lot of memory. If the max is small, it might have a bad effect on your algorithm (limits the connection-richness of the graph). The ideal situation is to have uniform and predictable edge counts (like in a d-ary tree), in which case, edge-lists can be inlined with minimum waste. I cannot guarantee uniform or predictable edge counts for the adjacency-list graph, so I can't inline them.

As for the actual look of the node structures, you didn't need to spell that out. I wasn't born yesterday.

The main question I had about that is when you said "stored flat in the partner node and relatively local". How do you achieve locality of the …

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

It is quite important that you explain what this actually is.

Ok, let me answer your questions.

The ostensible BST is not even a binary tree. So how can you possibly call it a BST, then?

By "not necessarily binary", I really should have said "d-ary". In other words, it's a d-ary search tree. If d = 2, then it is binary, otherwise it is not. This is simply because it doesn't matter, implementation-wise, whether d = 2 or not. The only point that matters is that it is a fixed fan-out tree.

I thought you were replacing your binary search tree with a B-tree.

Those two things are separate concepts. A binary search tree (like a red-black tree) denotes the logic (or algorithms) used to construct and maintain the tree structure. The B-tree is one way to store that tree. And, of course, it goes without saying that the concept of a B-tree works just as well for a d-ary tree. So, by B-tree, I really just mean a breadth-first layout for a fixed fan-out tree.

You can't "replace a binary search tree with a B-tree", you can choose to store the binary search tree in a contiguous array with a breadth-first layout (i.e., a B-tree for short). But there are alternative storage strategies, like a COB-tree, or even a linked-list-style tree (each nodes has pointers to child nodes, and so on), although the latter is going to have very poor performance. The …

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

I just wanted to point this out.
Another solution is to simply attempt to compile everything with the C++ compiler. Technically, a C++ compiler cannot compile any C code, but it can compile most C code. Of course, if the C code is a large code-base and all, you shouldn't do this; in that case, use the solutions given by VernonDozier and deceptikon. But if it is only a small piece of C code that you grabbed from somewhere and wish to use in a small project, then you might consider just trying to compile it with the C++ compiler, and if there aren't too many errors and warnings you can try to fix them to make the C code compilable in C++.

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

Thank you very much for the detailed answer! That's really helpful! Very much appreciated!

Let me layout a few terms that I'll use here to describe my setup:

B-tree: a breadth-first memory layout to store the nodes, their associated data, and the data associated to the edges of the tree (the details of this implementation are not so relevant). This component exposes a standard tree interface (set of functions like add-child, get-parent, etc.).
BST logic: an implementation of a binary search tree (in the very general sense). In actuality, this is a space partitioning tree (not necessarily binary either), so the logic is a bit more complicated than a simple red-black tree, for instance. Overall, the idea is that this code handles all the operations to look-up nodes, insert / delete, re-balance and so on. This code only deals with the standard tree interface (it is agnostic of the underlying data structure).
BST-data: data stored at the nodes or tree-edges that is used by the BST logic to do its work.
Adj-list graph: a general graph which has the exact same node-set as the B-tree, but allows for general inter-connections between them, i.e., an adjacency-list graph seems to be the only viable pattern to represent it. This component exposes a standard graph interfaces (those of the Boost.Graph Library).
Graph-algorithm: the algorithm (or set of algorithms) that use and require that general graph structure over the nodes. This code deals only with the standard graph interfaces.
Graph-data: data stored at the …

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

I know .NET is a Microsoft framework.

Yes.

I currently use Visual Studio 2008 for C++ programming in school. Am I using .NET?

Maybe. C++ is a programming language that is fundamentally incompatible with .NET. However, Microsoft has a frankenstein language called C++/CLI which mixes C++ with .NET code (and from my impression of it, it seems mostly intended (and used) as glue between real C++ code and real .NET code (e.g., C#), not as a standalone language). It might not be obvious to you which one you are using. But, technically-speaking, if you do C++ programming, then you are not using .NET, and if you do C++/CLI programming, then you are most-likely using .NET.

Here are some obvious signs that a given piece of code is in C++/CLI and not in C++.

  1. If standard library components use CamelCase convention, like String instead of std::string. All standard library components in C++ use all lower-case letters, usually underscore-separated.
  2. If you see things like System::Console::WriteLine( something ) as opposed to std::cout << something << std::endl;.
  3. If you see the character ^ anywhere. In C++, that character is not used for anything, and cannot appear in variable names either. In C++/CLI, it denotes a pointer.
  4. If you see things like ref class Something { to declare a class.
  5. If you see gcnew instead of new (gcnew means "garbage collected new"). In C++, there is no such thing as garbage to collect, so that doesn't exist.

and so on...

darkagn commented: An informative, concise and polite post +10
Perry31 commented: Thans Mike for your elaborate information and so patience +0
mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

Well, DeanMSands3 was right about one thing: the original loop was erroneous. The correct solution is this:

indices = malloc (sizeof(short) * data.face_count * 3);
for (i = 0; i < data.face_count; i++);  // notice i++ and not i += 3
{
    indices[3 * i]     = data.face_list[i]->vertex_index[0];
    indices[3 * i + 1] = data.face_list[i]->vertex_index[1];
    indices[3 * i + 2] = data.face_list[i]->vertex_index[2];
}

As for the weird behavior, it looks like a memory corruption to me. I would start by making sure the code is correct (like the above), and then start talking about "weird" behavior. In my experience, compilers (almost) never act in a weird way, but programmers do all the time!

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

I am currently working on kind of multi-graph structure. The thing is that two graphs are needed for my application which span the same vertices but with two distinct set of edges (i.e., a multi-graph). The first graph is a binary search tree, while the second graph must be general (directed / undirected, or bidirectional, possibly with cycles, etc.). The B-tree is used for fast queries of nearest nodes, while the second graph is needed for path-planning (e.g., in the style of shortest-path algorithms). Both graphs have to be completely mutable (reconnections, moving nodes around, adding/removing nodes and edges to either graphs). So far it's simple enough, just a multi-graph. A typical implementation of such a multi-graph (and similarly, a multi-index) would have all the nodes in one array (or list) and the two edge-sets as adjacency lists within the nodes, or, it would have two graphs that indirectly point to nodes in an array. This is simple to deal with because the nodes remain in fixed locations (or indices) in the array or list, and edges are easy to rewire and keep consistent with the node list.

However, for efficiency reasons (i.e., to solve locality of reference issues), I want to use specific memory layouts that are suitable for the binary search tree. In particular, I have an implementation of a breadth-first layout for the tree (i.e., BF-tree), as well as a cache-oblivious B-tree (or COB-tree) which have both proved to be orders of magnitude more efficient than a …