Re: Get list of unique words in a string



kangax wrote:
Thomas 'PointedEars' Lahn wrote:
kangax wrote:
Thomas 'PointedEars' Lahn wrote:
Thomas 'PointedEars' Lahn wrote:
Thomas 'PointedEars' Lahn wrote:
That is why I proposed "double hashing". Also, in my "double-hashed" "hash
table" implementation (that I wrote this morning) I use trailing underscores
instead because it is less likely that such property names are already used.
I'd still go for this solution instead, it is much more robust.
I'd love to take a look at your implementation.
You can find a first draft here:

<http://pointedears.de/scripts/test/map>

Constructive comments are welcome.

Is jsx.object available publicly? I see that Map is using its `isMethod`
only (?) but I would be interested to look at it overall.

Yes, consider the `script' elements. (It's a draft as well. `jsx.object'
is going to be the additional "namespace" provided by the next version of
object.js to avoid in-library incompatibilities with foreign scripts that
may declare/define the same identifiers. `jsx' is going to be the
additional "namespace" for all libraries of PointedEars' JavaScript
Extensions (as I have come to call it) for the same reason. Maybe I will
eventually abandon the global "namespace", but it is going to be supported
for a while longer for compatibility.)

A couple of questions regarding implementation:

1) Why do you declare functions in Map which don't use any of map
instance private variables? _hasOwnProperty, _maxAliasLength, _Value,
_Value.isInstance and few others could all be taken out of constructor
into the enclosing "wrapping" scope. Declaring them in Map seems
unnecessary and inefficient. Why waste time and memory redeclaring same
function objects over and over again?

_maxAliasLength is not a function but a "private property", so (AFAIK) it
must be declared in the constructor, accessible only through "public"
methods. _hasOwnProperty() accesses the "private" _items. And _Value()
(and _Value.isInstance) are defined within the constructor so that they are
unique for each Map object.

var Map = (function(){

...
var _hasOwnProperty = (function() {
return (jsx.object.isMethod(_items, "hasOwnProperty"))
? function(o, p) {
return o.hasOwnProperty(p);
}
: function(o, p) {
return typeof o[p] != "undefined";
};
})()

...
function Map(){}

...
return Map;

})();

Or am I missing something?

Yes, I think so.

2) Don't you think that _hasOwnProperty fallback - typeof o[p] !=
"undefined" - is a bit weak? Shouldn't you (at least) be comparing
property value to the value of the same named property of object's
`constructor.prototype`?

No, that would be the opposite of an equivalent to
Object.prototype.hasOwnProperty(). Please observe
that _hasOwnProperty() is called in _getSafeKey()
in a specific way.

3) I find it convenient to decouple unit tests as much as possible. Your
tests seem to depend on each other more than needed, so changing one
will affect another. Instead, why not create "clean" map in test
runner's "setup" method (I assume JSUnit should have such facility).

Good idea, will do.


PointedEars
.



Relevant Pages

  • [RFC] Towards a Modern Autofs
    ... The attached paper was written an attempt to design an automount system ... with complete Solaris-style autofs functionality. ... has exactly one daemon and one map associated with it. ... parent process's namespace. ...
    (Linux-Kernel)
  • Re: Default Directory Location??
    ... What we are talking about is a straight forward concept -- how to map names ... from one namespace to another. ... concept called a "virtual directory", which amongst many other things, ... > website, and then say that content for the /remote folder should come from ...
    (microsoft.public.inetserver.iis)
  • Re: Use the accessor! Was: Copy Constructor Usage
    ... I think you are getting too hung up on the copy constructor bit. ... accessor fns on some bogus efficiency argument. ... a field 'leng' might map onto an accessor 'size'; ... No style or design rules give us a free lunch. ...
    (alt.comp.lang.learn.c-cpp)
  • Re: confusing delete problem
    ... Joerg Toellner wrote: ... > thx for your replies. ... > Can't understand your comments about copy constructor. ... > definitely ONE instance/object of type class map. ...
    (comp.lang.cpp)
  • Re: confusing delete problem
    ... Of course x is defined in the real code destructor. ... Can't understand your comments about copy constructor. ... definitely ONE instance/object of type class map. ...
    (comp.lang.cpp)