|
Cool , always learning ,I love CP, I don't known very well the hash algorithms, do you known some good resource where it explains the basic terminology and optimizations on the algorithms like this one on maps, besides the normal computer science books ?
Cheers,Joao Vaz
And if your dream is to care for your family, to put food on the table, to provide them with an education and a good home, then maybe suffering through an endless, pointless, boring job will seem to have purpose. And you will realize how even a rock can change the world, simply by remaining obstinately stationary.-Shog9
|
|
|
|
|
No. I make this stuff up on the fly, test it, and then hope I am not talking out of my arse. (OMG, my secret is out.)
In all seriousness, that simple string optimization is from my work with the Forth language in the 80s. They had to deal with a wealth of symbols stored in a 4 wide hash table.
Darn it. I just was looking for a resource that I found last night that talked about a lot of hash optimizations. Can't seem to find the one I liked.
I did find this...
http://ciips.ee.uwa.edu.au/~morris/Year2/PLDS210/hash_tables.html[^]
Tim Smith
I'm going to patent thought. I have yet to see any prior art.
|
|
|
|
|
Tim Smith wrote:
and then hope I am not talking out of my arse.
Experience, experience
Tim Smith wrote:
Forth language in the 80s.
, I'm must admit that the 1st time that I've heard of Forth was here on CP when Valer Bocan posted his Forth compiler for .NET
Tim Smith wrote:
http://ciips.ee.uwa.edu.au/~morris/Year2/PLDS210/hash_tables.html[^]
Thanks, the article is nice and not too difficult to follow up
Cheers,Joao Vaz
And if your dream is to care for your family, to put food on the table, to provide them with an education and a good home, then maybe suffering through an endless, pointless, boring job will seem to have purpose. And you will realize how even a rock can change the world, simply by remaining obstinately stationary.-Shog9
|
|
|
|
|
One thing I noticed.
That article talked about rehashing to attempt to find an empty slot. When I say rehash, I mean using some heuristic to detect that the depth of the hash has become too large, thus triggering a resize of the hash table requiring all keys to be rehashed back into the larger table.
Tim Smith
I'm going to patent thought. I have yet to see any prior art.
|
|
|
|
|
Tim Smith wrote:
That article talked about rehashing to attempt to find an empty slot. When I say rehash, I mean using some heuristic to detect that the depth of the hash has become too large, thus triggering a resize of the hash table requiring all keys to be rehashed back into the larger table.
... and there will be light !!! Thanks, I didn't quite understand this part .
I must understand better some algorithms , it makes a hell of a difference .
Cheers,Joao Vaz
And if your dream is to care for your family, to put food on the table, to provide them with an education and a good home, then maybe suffering through an endless, pointless, boring job will seem to have purpose. And you will realize how even a rock can change the world, simply by remaining obstinately stationary.-Shog9
|
|
|
|
|
I did a performance analysis of my whole program and it turned out that hash_map was the least of my problems.
check this out
http://www.codeproject.com/script/comments/forums.asp?msg=323560&forumid=4486#xx323560xx
This is my hash_compare implementation. It works quite well. As you can see, I increased the starting bucket size to 512 and it works well. I am not at all concerned abut a little higher memory usage
<code>
namespace std
{
struct str_hash : public binary_function<size_t, char, size_t>
{
inline size_t operator() (const size_t hash, const char c)
{
return (hash<<5) + hash + c;
}
};
template<> class hash_compare <string, less<string> >
{
less<string> comp;
public:
enum
{
bucket_size = 4,
min_buckets = 512
};
inline size_t operator()(const string& k) const
{
return accumulate(k.begin(), k.end(), 0, str_hash() );
}
inline bool operator()(const string& k1, const string& k2) const
{
return k1 > k2;
}
};
}</code>
modified 29-Aug-18 21:01pm.
|
|
|
|
|
LOL, been there done that.
I love Vtune since it helps me to avoid thinking the wrong thing is bottle neck. I can not recomend Vtune enough. (Even though Intel's support sucks really bad.)
I have to admit that I was a tiny bit skeptical that the extra Dink compare would have made that much of a difference. Especially since the extra compare was there to help avoid running down the whole chain in the case of a failure to match.
Tim Smith
I'm going to patent thought. I have yet to see any prior art.
|
|
|
|
|
i could not suspect a member variable in a class causing such a problem, until I profiled it.
Thomas
modified 29-Aug-18 21:01pm.
|
|
|
|
|
Hi guys, I'm in a situation where my code (a steaming mass of it) makes heavy use of stl [strings]. I now need to convert my code so that it's fully unicode compliant. Out of curiosity I simply exchanged wstring for string and included [xstring] and recompiled. So there's now a million or so compiler errors being spewed out. That was expected, but whats the best way to go about performing such a conversion? I've noticed for example that the "==" operator doesn't seem to be supported by stl's unicode string class. I expect there to be many more issues as well.
If you know of a good site I can visit on the issue (I just want to get it over with pretty quickly) please supply a url. Currently, google spits out everything BUT discussions on stl unicode support.
Thanks guys!!
Senkwe
ASP.NET can never fail as working with it is like fitting bras to supermodels - it's one pleasure after the next - David Wulff
|
|
|
|
|
Ok, scratch that, MSDN came to my rescue (surprisingly). I was wrong on so many levels.
Cheers
ASP.NET can never fail as working with it is like fitting bras to supermodels - it's one pleasure after the next - David Wulff
|
|
|
|
|
Hehehe, don't you just hate when that happens.
Tim Smith
I'm going to patent thought. I have yet to see any prior art.
|
|
|
|
|
I always just declare my own tstring :P
typedef std::basic_string<TCHAR> tstring;
"The greatest danger to humanity is humanity without an open mind." - Ian Mariano
http://www.ian-space.com/
|
|
|
|
|
Hi,
I have a an out of process COM EXE that runs on local server.
This (.EXE) is statically linked to a dll. There are 3-4 directories in which
the set of dlls reside (different versions of dll), and I have to decide which set of dlls to use at run time.
This is what I try in the calling program:
Get the current environment variable (using GetEnvironment Variable)
Append the chosen dll folder (from the set of 3-4 folders, because by this
time I know which set of dlls to use) to the PATH variable
Call SetEnvironment Variable.
Now call Coinitialize() and CoCreateInstance()...
I expect the COM EXE to come up using the overridden PATH variable because
the child process is supposed to inherit the parent's environment.
While this is behaving as expected in most cases, in certain cases it is
not behaving the way I want it to behave. At times (especially when called from within an NT service), the COM EXE does not inherit the revised PATH variable but instead inherits the original PATH variable.
What are the situations when CoInitialize() results in initializing the COM EXE with a different environment than the parent? Is there any way to force the child to inherit the revised PATH variable from the parent?
Regards,
Gopi
|
|
|
|
|
Like topic says. I try to stay away from MFC as much as possible but I need to convert some MFC classes to ATL and I haven't found equivalents to those 2 classes.
Anyone knows?
Thanks!
---------------
Concentrating on Ideas
http://www.edovia.com
|
|
|
|
|
If you are using ATL7 then you get some good array/list templates - CArray<> and CList<>/
|
|
|
|
|
MSHTML certainly parse HTML code.
For Example,,,
To,,
I want to stop parsing.
Since MSHTML is automatically parse the moment I inputted the character, I am in trouble.
Please help me!!
|
|
|
|
|
The key thing that you need to do is use the IPersistStreamInit interface. This will allow you to get the data. This function goes a step further and verifies that IE is holding a HTML doc, however you could change this to grab any data.
HRESULT GetDocumentContent(IWebBrowser2 *pWebBrowser2, CComBSTR &bstrHTMLText)
{
bstrHTMLText.Empty();
CComPtr<IDispatch> pDisp;
HRESULT hr = pWebBrowser2->get_Document(&pDisp);
if (FAILED(hr))
{
return hr;
}
CComQIPtr<IHTMLDocument2, &IID_IHTMLDocument2> spHTML = pDisp;
if (spHTML)
{
CHAR *szData = NULL;
OLECHAR *htmlText = NULL;
try
{
CComQIPtr<IPersistStreamInit, &IID_IPersistStreamInit> spData = spHTML;
CComPtr<IStream> spStream;
::CreateStreamOnHGlobal(NULL, TRUE, &spStream);
spData->Save(spStream ,FALSE);
STATSTG stat;
spStream->Stat(&stat, STATFLAG_NONAME);
szData = new CHAR[stat.cbSize.LowPart];
ULONG length;
LARGE_INTEGER pos;
pos.QuadPart = (__int64)0;
spStream->Seek(pos, STREAM_SEEK_SET, NULL);
spStream->Read(szData, stat.cbSize.LowPart, &length);
htmlText = new OLECHAR[length];
::MultiByteToWideChar(CP_ACP, 0, szData, length, htmlText, length);
bstrHTMLText = htmlText;
}
catch (...)
{
}
delete[] htmlText;
delete[] szData;
}
else
{
}
return S_OK;
}
Build a man a fire, and he will be warm for a day Light a man on fire, and he will be warm for the rest of his life!
|
|
|
|
|
Thank you,
But I could'nt.
That's source complied suceedly.
And, HTML Code was put.
,,,,,
I want to read original HTML code.
Example,,
Original:
a
bc d
MSHTML:
a bc d
I want to put original source.
|
|
|
|
|
Í have the following problem, my app (wtl exe)loads dll´s dynamically (also wtl NOT COM) which display dialogs(pages) on a client area of my main app (also a dialog). The problem that I´m having, is that when changing between pages I check for valid data before displaying the next/chosen page. This checking is performed in the dll(in the class that wraps the page), and on an error, should display a MessageBox. However, the messagebox is NOT Modal, and is destroyed after being visable for 1 second or so... 'I´ve even gone as far as changing my dll interface to take a HWND of the main apllication so that I can call the messagebox so...
int nRet = ::MessageBox(hWndOfMainApplication,"Bollocks!", "Error!", MB_OKCANCEL | MB_TASKMODAL);
I´m at my wits end and don´t know why this is happening,
Any Ideas???
Thanks in advance
Phil
bum... and I thought I´d got rid of all the bugs
|
|
|
|
|
Anyone could point me to a nice tutorial so I can learn how to access an Access database with SQL queries? What I did so far is to use the ATL OLEDB Consumer in the class wizard and create a consumer that uses CCommand. The documentation I found on MSDN is quite confusing...
I used to do this quite easily with MFC but it seems a nightmare to do (at least to understand) with ATL... I almost regret not including support for MFC in my ATL project...
Thanks guys!
---------------
Concentrating on Ideas
http://www.edovia.com
|
|
|
|
|
ATL consumers provide database access using OLE DB - the most efficient way to access SQL database. OLE DB however has relatively steep learning curve. One thing you can do to quickly be able to deal with databases in your ATL project - is to use ADO instead. ADO is a VB-friendly layer on the top of OLE DB. Just import ADO type library by including it in your stdafx.h:
#pragma warning(disable:4146)
#import <msado15.dll> no_namespace rename("EOF", "_EOF")
#pragma warning(default:4146)
Then you can use ADO interfaces in your project (check MSDN documentation). It's not as efficient as OLE DB (single fields are converted into VARIANTs), but it's a quick and easy start.
Forget about MFC database classes in ATL. MFC only supports ODBC.
Vagif Abilov
MCP (Visual C++)
Oslo, Norway
Hex is for sissies. Real men use binary. And the most hardcore types use only zeros - uppercase zeros and lowercase zeros.
Tomasz Sowinski
|
|
|
|
|
Vagif Abilov wrote:
OLE DB however has relatively steep learning curve.
Not with the ATL-classes...?
It's the same old procedure; issue query, move to top, scan and process until end.
With VS.NET and attributed classes, it's as simple as ADO I'd say - without the VARIANT-mess.
--
Master, I'm so glad to feel your presence. But you don't seem to share my impatience. I relied upon you to break the silence. I cannot understand your reluctance.
Master, I feel so warm and I'm so happy, oh master.
Give me some more of the warm little beasts
I'm so fond of.
|
|
|
|
|
I'm trying to figure out a way to easily parse and formating date/time values using STL. Unfortunately, I can't seem to find much information regarding the time_get and time_put facets. I can use strftime and the other associated crt calls but I would prefer to stay in stl for this if I can.
Does anyone have a good sample, or reference to a sample on how to do this?
Thanks in advance,
Shawn Nagase
|
|
|
|
|
Does anybody knows how can I solved the following problem.
When I make a ATL Project with the ATL/WTL AppWizard and I try to use the ClassWizard, I get the following error:
The ClassWizard database c:\app\app.clw does not exist. Would you like to build it from your sorce files?
After selecting my source files, it won't rebuildem.
Does anybody knoes how can I correct(prevent) this problem.
This happens also in my first time Visual C++ installation.
|
|
|
|
|
ClassWizard is for MFC apps. For ATL, you can right-click a class in ClassView, and if it's a window class the menu will have "add message handler" and other commands for adding handlers to the ATL msg map.
--Mike--
"I'd rather you just give me a fish today, because even if you teach me how to fish, I won't do it. I'm lazy." -- Nish
Just released - 1ClickPicGrabber - Grab & organize pictures from your favorite web pages, with 1 click!
My really out-of-date homepage
Sonork-100.19012 Acid_Helm
|
|
|
|
|