|
"When you realize you don't know what you thought you knew" ... that is when you, very temporarily, most often without suspecting it, have wisdom.
If (may the gods spare me) I had to emulate a .NET Dictionary in EcmaScript, I would be tempted just to make sure the 'Add function failed if the candidate Key was a duplicate, but I like the fact you are going for the full-monty, hash, and all.
cheers, Bill
«There is a spectrum, from "clearly desirable behaviour," to "possibly dodgy behavior that still makes some sense," to "clearly undesirable behavior." We try to make the latter into warnings or, better, errors. But stuff that is in the middle category you don’t want to restrict unless there is a clear way to work around it.» Eric Lippert, May 14, 2008
|
|
|
|
|
|
I'm probably missing something here, but why do you want to reinvent the wheel?
No, there are no dictionaries in javascript <spit>, it's untyped afterall. But if you call them by the normally accepted name, associative array, you'll notice it's already built in, even in such a backwards language as javascript <spit>.
More info here: JavaScript <spit>- Objects as associative arrays[^]
|
|
|
|
|
I know objects are implemented as associative arrays so JavaScript kind of has a Dictionary.
JavaScript also has an array that sort of acts like a list (but "add" is called "push", it's also a queue and a stack, it doesn't even have a decent "contains" function (it does in newer browsers, but it's called "includes", because that's what it's called everywhere else, right?), etc.).
So, just like everything else in JavaScript, arrays and associative arrays suck, that's why I'm making my own
|
|
|
|
|
Ok fair enough, I suspected I was missing out something.
But I would assume the builtin funtions are a bit better optimized than anything you can implement yourself, so I would probably just try to add the missing functionality to the builtin arrays rather than starting over from the beginning.
|
|
|
|
|
"Premature optimization is the root of all evil" - Donald Knuth
|
|
|
|
|
Donald Knuth didn't know about javascript <spit> then.
|
|
|
|
|
I'll be sure to test for performance then
|
|
|
|
|
Hi Jorgen,
I doubt Donald Knuth ... in his worst nightmare ... could have ever imagined an enterprise with the scope of the WWW that would converge on using a lingua franca of a screwed up scripting tool, named after a language it had nothing to do with, stretched like a yogic contortionist to fit containers it never belonged in, patched-up with all kinds of graphic/widget extension junk, super-glued together with a half-assed mark-up language, duct-taped to a half-assed meta-mark-up style language, with all the flaws of Visual Basic ...
becoming a standard because it was the only "neutral ground" the major power$-that-be who ate the web, and are now digesting it into cash, could, by default, mutually tolerate.
Do I need to say that I don't like JavaEcmaScript ?
cheers, Bill
«There is a spectrum, from "clearly desirable behaviour," to "possibly dodgy behavior that still makes some sense," to "clearly undesirable behavior." We try to make the latter into warnings or, better, errors. But stuff that is in the middle category you don’t want to restrict unless there is a clear way to work around it.» Eric Lippert, May 14, 2008
|
|
|
|
|
|
Sander Rossel wrote: Why DOES an IEqualityComparer have a GetHashCode AND an Equals function anyway?
(Just in case you weren't just asking rhetorically...)
Imagine Webster's Dictionary on your desk and you want to look up the word "Elephant". The Hash function lets you turn immediately to the page "ECMAScript to Elephanting", and the Equals function finds the specific word on the page. (A good summary is here .)
|
|
|
|
|
Thanks for the answer, but I knew (already looked it up)
|
|
|
|
|
var dictionary = {};
Done.
|
|
|
|
|
dictionary["Hi"] = "Hi";
dictionary["Hi"] = "Bye";
var o = dictionary["Bye"];
dictionary.forEach();
dictionary.toArray(); It's really not the same
|
|
|
|
|
Key-value pairing is sufficient for dictionary. It has amortized O(1) store, O(1) search/retrieve. There are one-liners for loop and conversion to array:
Object.keys(o).forEach(...);
Object.keys(o).map(i => o[i]);
But if you want more specialized non-dynamic dictionary, you can create your own class. The point was that is not true, that JS lacks of hash function for every value (it is just internal). It is a messed up language for lack of proper handling of primitive types, operator overloading and so on, but lack of hash function is not one of the reasons.
|
|
|
|
|
Plamen Dragiyski wrote: not true, that JS lacks of hash function for every value (it is just internal) To a user (me), having it internal is the same as non-existing as I still can't use it
Plamen Dragiyski wrote: But if you want more specialized non-dynamic dictionary, you can create your own class Exactly
|
|
|
|
|
Sander Rossel wrote: I thought I knew how it worked (I've written a few), but apparently I didn't.
That happened too many times in my life as a programmer. So I stopped assuming I know, to just accept my ignorance.
It even makes me happier so I know I will always have something new to learn.
To alcohol! The cause of, and solution to, all of life's problems - Homer Simpson
Our heads are round so our thoughts can change direction - Francis Picabia
|
|
|
|
|
Ignorance is bliss
|
|
|
|
|
So true
To alcohol! The cause of, and solution to, all of life's problems - Homer Simpson
Our heads are round so our thoughts can change direction - Francis Picabia
|
|
|
|
|
So, I read this crazy long articleThe Artificial Intelligence Revolution: Part 1 - Wait But Why[^] which has actually been out for nearly 2 years now - I'm sure many of you have come across it. But I can't help but feel that there are things at play in this whole thing other than what the article mentions...
For one, it mentions that if we could somehow make a self-learning computer which is on the same level of humans, which would be called AGI - Artificial General Intelligence, then the jump from AGI to ASI would be super fast... Basically, this computer will harness the inherent advantages of a computer system over the human brain and essentially learn everything we've learned plus billions more times over at an exponential rate, at which point the computer will be to us as we are to an ant, in terms of intellect and smarts.
However, when reading through this, I can't help but ask this question though: Assuming a computer COULD jump online and essentially dig into all of our knowledge and "understand" it, that would still only allow it to access human knowledge. How is it going to derive super-intelligence from only having access to human-intelligence information? Supposedly, the arguments are out that if a computer reaches AGI, then within small order it will suddenly be billions of times more intelligent than a human... But there are only a finite number of actual resources for an intelligent computer to access... And they are written by humans.
In other words, say a lion makes a special machine that could learn from it, other lions, and progress... But it only had access to lion knowledge and was in itself built by a lion - meaning with the limitations of a lion... How would that machine now suddenly dive into an entire other dimension of intelligence?
Even if we made a machine which properly emulates/mimics the human mind... Then we are making a machine which mimics the human mind - meaning it has flaws and it is not superior to it. I feel like a superior race or more intelligent being could supply such a computer with advanced intelligence, but operating out of the human knowledgebase, that isn't quite likely.
Not only that, but we must also consider trial and error. Only so much can be learned from reading and processing written/online information... Some things, this AI would have to test out for itself, and not everything is a video game - meaning, the act of actually experiencing trial and error, would take time, much like it does for a human: In order to learn from mistakes made during an interview, I must first actually go to that interview, and since said interview is not until a month from now, I must now wait.
I understand where they're going with the concerns in the article, but at the same time, let's face it: stuff never turns out exactly how we imagine... And I find it unlikely that humans would be able to craft a machine that will somehow within a day or two of reading/analyzing human-made material, become billions of times more educated than humans and then take over...
Because human-made material is flawed. How many times have you read 3-5 books and still had questions or found that some are wrong even...
Food for thought.
modified 18-Sep-16 7:35am.
|
|
|
|
|
I saw it a lot of times that even the most intelligence are confused between intelligence and knowledge...
It is entirely possible that a well designed artificial brain will be able to gain knowledge in a way no other brain can, but that will not make it more intelligent...
Skipper: We'll fix it.
Alex: Fix it? How you gonna fix this?
Skipper: Grit, spit and a whole lotta duct tape.
|
|
|
|
|
That argument is not about the magic acquisition of knowledge out of nowhere, it's about the idea that a digital intelligence could rewrite itself so it can think faster/better. And once it does that a bit, it gets even better at that, and so forth.
Which makes sense, I guess, though I see no reason to give an AI that capability unless specifically setting out to find out what it will do with it. I mean just because you're an AGI doesn't mean you're allowed to modify your code and recompile yourself. For example it's not like a bunch of simulated neurons (supposing we go that way) could actually do anything, unless we explicitly link their output to some action.
|
|
|
|
|
Yeah I was thinking the same thing: the computer could be as intelligent as it wants, but it must have an output method to actually perform work. Plus, raw intelligence does not always win. For example, say Einstein got into a fight with a gang member: chances are, Einstein would be far more intelligent... Chances are, Einstein would get his ass kicked. Hell, there are humans who jump into zoo enclosures and get killed by animals.
There seems to be this notion that just because an ASI machine gathers more intelligence than us, that it will automatically take over, but there is more to that than raw intelligence. There would have to be reproduction, manpower, output capabilities, etc...
True, technically it could manipulate humans to carry out its "master plan" but, this is starting to sound like a bad movie, LOL.
|
|
|
|
|
TheOnlyRealTodd wrote: chances are, Einstein would be far moretoo intelligent... to get into a fight with a gang member
FTFY
If you have an important point to make, don't try to be subtle or clever. Use a pile driver. Hit the point once. Then come back and hit it again. Then hit it a third time - a tremendous whack.
--Winston Churchill
|
|
|
|
|
Indeed it does, but how are you going to stop a mad scientist from giving it an output method? And giving it the ability to use its output method to add more output methods?
An AI computer, even if itself quite limited to start off, is an unimaginably power thing. With all the knowledge of humanity at its instant disposal, it can easily hack and take over other systems that it deems moral and beneficial. It would be nearly impossible to stop without a kill switch.
Basically it comes down to this - whoever creates the first such machine, does their best to program their intentions, desires and morals into this machine and hits the power button to set it loose will be the people that determine the fate of the world, for better or worse, and possibly the universe. They will literally be able to shape the future of the entire universe based on how well they transferred their ideas into code.
I think it will be virtually impossible to prevent this from happening shortly after the capability is there. Maybe some clever humans will find a way to effectively control computing but I doubt it. So then it becomes a race of who unleashes their AI first, because who wants to be at the whim of someone else's AI, set to their own ideals and morals? Not I.
|
|
|
|
|