Hi,
I am converting a C file to C++. Since the functions will still be called from C code I will place the entire file in extern "C" block.
The file contains following code-
struct node{
char* name;
struct node* next;
};
static struct node* list; //file scope
void insertInList(FILE*){
read file line-by-line and add names present in file to the list
}
bool isNamePresent(char* name){
//iterate through Linked-list & returnt true if present
}
Now, it appears to me that the complexity of 'isNamePresent' can be improved by using unordered_set<string> . But, looking at customer usage it appears that generally few names are entered in the list.(sometimes it is just 1)
Q1) So, should I still change the code to use unordered_set? Will it be still considered a good change in terms of performance or any other terms?If so please explain why??
Also, does scenarios like "what if user enters hundred thousand names in file" are considered during software development when we know the general use pattern?
Q2) How should I write the set in the file? What is the difference between following lines written in global space-
static std::unordered_set<std::string> st;
vs
namespace{
static std::unordered_set<std::string> st;
}//anonymous namespace
Is the first one initialized with some garbage value?
Regards,
Abhishek Gupta