Topic: std::set< std::set<T> >
Author: =?iso-8859-1?Q?Juli=E1n_Calder=F3n_Almendros?= <jcalderon@jet.es>
Date: 1999/06/01 Raw View
Valentin Bonnard <Bonnard.V@wanadoo.fr> escribi=F3 en el mensaje de notic=
ias
374E8A21.1B7@wanadoo.fr...
> Juli=E1n Calder=F3n Almendros wrote:
>
> > The problem is the ' std::set '.
>
> std::set corresponds to the mathematical notion of a typed set
> of objects of type T. Well, not all operations on set corresponds
> to a mathematical set.
>
For example, set_intersection of header file <algorithm>. This algorithm =
put
the
result in the iterator OI, but how do I applicate it to container set?. I
may
utilite the member function insert of set<T> class, no the assignation
through
the iterator (if I assign through the iterator, I could repeat the same
element
several times).(?).
On the other hand the set that I want construct is set<int>, int is inclu=
ded
into [a,b], where a and b are unsigned int, being the set<int> a finite s=
et.
The
other set is set power of the first set. It is too of finite type. But wh=
ile
the
set<int> is a totally ordered the set< set<int> > is not totally ordered.=
If
I
take the lexicographical order for the set< set<int> >, I missing efficie=
nce
because the natural order of individuals set<int> is the inclussion, and =
I
take
an different order relation for search, etc.
Is it true?.
>
> > For it unites application it is necessary
> > me, incredibly, a set-set (in the mathematical sense). that is to say
that
> > interests me ' std::set <T> ' and ' std::set <std::set <T>> ',
> > you already know, a set of the parts of that set (set that is power o=
f a
set).
>
> BTW, the Set Theory is an untyped theory. std::set<T> has a type
> different from T, and you cannot write
>
> typedef std::set<T> T;
>
> in C++ (sadly ?).
In Set Theory we have very much care with the elements and the set, no?,
because
the object of type T can't belong T. T is included in T but T don't belo=
ng
T.
So I don't understand the motive to write the before line of C++.
>
> > The intringulis is that the ordination makes it by means of the '
operator
> > <' of 'std::set <T>' that have had to overload.
>
> The same thing as in all containners: it's the lexicographic
> ordering. This is a general requirement. It may be unfortunate
> for sets and multisets.
There are more people with problems with std::set to use in the mathemati=
cal
sense?.
>
> > The ' <' it consists in it unites
> > strict inclusion.
>
> No.
I don't speak Inglish well, and I doub over that I have been said. The
strict
inclusion I know that isn't a total realtion of order. But, all relations=
of
order to use with the STL containers could be of total order?.
There exists containers (some type of tree or grafo) to eficcient use of =
set
with a strict order relation but no total?.
>
> And here this the problem. When I insert objects of the
> > type 'std::set <T>', be A, B and C, insert them if they are not
equivalent,
> > and not if they are not same (I also have overloaded ' operator =3D=3D=
').
>
> You don't need to, except if you want to use =3D=3D on sets.
> std::set never compare its elements with =3D=3D (again,
> except when you compare sets with =3D=3D).
>
> > And in this case
> > equivalence and equality (in the sense of the STL) they don't coincid=
e,
>
> Of course they do (provided they do on your class T).
>
> > If somebody has solutions or he/she knows some place of the web where=
to
> > look for, I thank him the information.
>
One idea is:
1) The typename T, could be
template<T>
struct tipo {
T value;
bool belong;
};
2) The second step is to define the constructor of set<tipo<T> > so to
include
the void set, but with the tipo::belong=3D=3Dfalse.
3) The three step is overload the function insert. I'll have 2 insert
functions.
One insert with the tipo::belong =3D=3D false and the other with the
tipo::belong =3D=3D
true.
4) The general insert, first find the set_individual to insert, if there
exits
with tipo::belong=3D=3Dfalse I put the tipo::belong =3D=3D true. If there=
exist
'belonging', not insert.
5) If the set_individual is not in the tree (in the set), I could insert=
of
the
natural way.
6) If the set_individual was not introducing into the set of a set, then
introducing the union of the set_individual with the greater set_individu=
al
(with the tipo::belong =3D=3D false). Then I insert the individual_set by=
normal
insert.
What do you think about this?.
Thanks.
Julian Calderon Almendros.
jcalderon@jet.es
_____________________________________________________________________
"Al principio estaba Eru, que en Arda es llamado Illuvatar, ..." de JRR
Tolkien.
Quisiera mirar por las estancias de Ea y ver la ilusi=F3n que Eru provoc=F3=
en
la mente de los Ainur.
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: Valentin Bonnard <Bonnard.V@wanadoo.fr>
Date: 1999/06/01 Raw View
: Valentin Bonnard <Bonnard.V@wanadoo.fr> escribi=F3 en el mensaje de
notic=
: ias 374E8A21.1B7@wanadoo.fr...
: > Juli=E1n Calder=F3n Almendros wrote:
: >
: > > The problem is the ' std::set '.
: >
: > std::set corresponds to the mathematical notion of a typed set
: > of objects of type T. Well, not all operations on set corresponds
: > to a mathematical set.
: >
: For example, set_intersection of header file <algorithm>.
For sets, this really computes set intersection as defined in
set theory.
: This algorithm put the result in the iterator OI, but how do I
: applicate it to container set?
std::std::iterator isn't modifiable (when you dereference it, you get
a const T&). This means that you cannot ever write:
set_intersection (s1.begin(), s1.end(), s2.begin(), s2.end(),
s3.begin());
Well, you generally cannot do that with vectors either, because it will
overwrite elements and you want to insert elements.
What you should do (in both cases) is to insert elements, not overwrite:
// [s1.begin(), s1.end()) and [s2.begin(), s2.end()) are sets
// (s1 and s2 may be vector<>s, list<>s, set<>s or multiset<>s)
set_intersection (s1.begin(), s1.end(), s2.begin(), s2.end(),
insert_iterator<I don't remember>(s3));
: On the other hand the set that I want construct is set<int>, int
: is included into [a,b], where a and b are unsigned int, being the
: set<int> a finite set.
A finite set is bounded, is that what you saying ?
: The other set is set power of the first set. It is too of finite
: type.
You mean that it is finite too, don't you ?
: But while the set<int> is a totally ordered the set< set<int> > is
: not totally ordered.
Every set, finite or infinite, has a total order. (And you can
add other interresting properties to this order, such that it is
well-founded -- that's beyond my point anyway).
: If I take the lexicographical order for the set< set<int> >,
: I missing efficience because the natural order of individuals
: set<int> is the inclussion, and I take an different order
: relation for search, etc.
???
: Is it true?.
I don't even understand what you are saying.
: > > For it unites application it is necessary
: > > me, incredibly, a set-set (in the mathematical sense).
I don't know the mathematical meaning of set-set. Actually,
I have never seen this term anywhere.
: > > that is to say that
: > > interests me ' std::set <T> ' and ' std::set <std::set <T>> ',
: > > you already know, a set of the parts of that set (set that is
: > > power of a set).
: >
: > BTW, the Set Theory is an untyped theory. std::set<T> has a type
: > different from T, and you cannot write
: >
: > typedef std::set<T> T;
: >
: > in C++ (sadly ?).
: In Set Theory we have very much care with the elements and the
: set, no?, because he object of type T can't belong T.
It depends. If you outlaw it, then it cannot happen. I you don't then
it can.
: T is included in T but T don't belong T.
Again it depends. {{{{{{{...}}}}}}} certainly belongs to itself.
^^^^^^^
There is an infinite number
of { and } here
But again that's beyond my point. My point is that sets contain
sets.
: So I don't understand the motive to write the before line of C++.
Because mathematical sets contain nothing but sets.
: > > The ' <' it consists in it unites
: > > strict inclusion.
: >
: > No.
:
: I don't speak Inglish well, and I doub over that I have
: been said.
I am not a native English speaker either, you know.
: The strict inclusion I know that isn't a total realtion
: of order.
Correct. For example, {1} and {2} aren't ordered by inclusion.
: But, all relations of order to use with the STL containers
: could be of total order?.
You mean: Does set<T, Order> expects Order to be a total order
over T ?
The answer is yes, except that it's total over
T
--------------
Equiv(Order)
Where Equiv(Order) is the equivalence relation induced by the
order Order.
: There exists containers (some type of tree or grafo) to eficcient
: use of set with a strict order relation but no total?.
I don't see how such a thing would be possible in general.
Anyway, you don't want to do that.
Conclusion: it appears that you are very confused, both about
the STL and about mathematical sets.
For information about the STL, there are many good books (as
well as really bad ones). There many books which explain set
theory, which is a fascinating field, but I don't think that
you need to understand it to use the set algorithms in the
STL.
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: Pete Becker <petebecker@acm.org>
Date: 1999/06/02 Raw View
Valentin Bonnard wrote:
>
> insert_iterator<I don't remember>(s3));
>
I don't remember, either. Which is why the standard provides for
back_inserter(s3), etc.
--
Pete Becker
Dinkumware, Ltd.
http://www.dinkumware.com
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]