Re: set intersection -> true/false



Willem <willem@xxxxxxxx> wrote in message news:<slrnd9og8b.826.willem@xxxxxxxxxxxxx>...
> If you can use STL, haven't you got a hash table implemented already ?
> It may be called a map or mapping or something like that.

yes. maps.
>
> In any case, a hash table (or whatever it's called) is, for this problem,
> a datatype where you can check in O(1) time if a given entry is already
> in the table. Usually hash tables have 'keys' and 'values', but in this
> case you just need the 'keys'.

i think i'll just copy the STL source code for set-intersection and
modify it (for me) to stop after first occurence.. I have these 2 sets
- (ordered; unique lists), i iterate through both; iterators just go
further when they are smaller than the other one, simetrically, and if
equal, return true instead of storing in the third iterator. Then one
goes just one time through the sets.
With maps i still don't see how to make the comparison...but thanks
again.
.



Relevant Pages

  • Re: If you are unhappy with the direction of Ruby 1.8.7+, respond
    ... the order that keys appear in a literal, ... -- except that if you iterate twice, ... hash values of the keys, The iteration is over the hash buckets and hash ... But that's just a side-effect of the hash of a fixnum being ...
    (comp.lang.ruby)
  • Re: If you are unhappy with the direction of Ruby 1.8.7+, respond
    ... the order that keys appear in a literal, ... -- except that if you iterate twice, ... hash values of the keys, The iteration is over the hash buckets and hash ... But that's just a side-effect of the hash of a fixnum being ...
    (comp.lang.ruby)
  • Size of a hash
    ... use the keys() function in a scalar context to get the number of ... key-value pairs in the hash. ... To iterate through an entire hash, ... But it still sounds as if you're really asking about an array. ...
    (perl.beginners)
  • Re: Hash#each vs Hash#each_pair
    ... Array#each both iterate through the values of the container. ... hash, yielding the keys and the values makes sense too. ... Ernest Hemingway ...
    (comp.lang.ruby)
  • Re: Proposal/RFQ: Hash#values/keys with block
    ... #keys should return the hash's keys, IMHO it shouldn't iterate over ... How can one program in Ruby and _not_ know that classes ... I'm arguing in favour of this extension of these Hash methods because ...
    (comp.lang.ruby)