~ubuntu-branches/ubuntu/intrepid/tcm/intrepid

« back to all changes in this revision

Viewing changes to src/sd/bv/bag.h

  • Committer: Bazaar Package Importer
  • Author(s): Otavio Salvador
  • Date: 2003-07-03 20:08:21 UTC
  • Revision ID: james.westby@ubuntu.com-20030703200821-se4xtqx25e5miczi
Tags: upstream-2.20
ImportĀ upstreamĀ versionĀ 2.20

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//////////////////////////////////////////////////////////////////////////////////
 
2
// This file is part of Toolkit for Conceptual Modeling (TCM).
 
3
// (c) copyright 2001, Universiteit Twente.
 
4
// Author: Rik Eshuis (eshuis@cs.utwente.nl).
 
5
//
 
6
// TCM is free software; you can redistribute it and/or modify
 
7
// it under the terms of the GNU General Public License as published by
 
8
// the Free Software Foundation; either version 2 of the License, or
 
9
// (at your option) any later version.
 
10
//
 
11
// TCM is distributed in the hope that it will be useful,
 
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
// GNU General Public License for more details.
 
15
//
 
16
// You should have received a copy of the GNU General Public License
 
17
// along with TCM; if not, write to the Free Software
 
18
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 
19
// 02111-1307, USA.
 
20
////////////////////////////////////////////////////////////////////////////////
 
21
 
 
22
//------------------------------------------------------------------------------
 
23
#ifndef _BAG_H
 
24
#define _BAG_H
 
25
 
 
26
#define MAXLENGTH 200
 
27
 
 
28
#include "element.h"
 
29
#include "bool.h"
 
30
#include "llist.h"
 
31
#include "subject.h"
 
32
#include "adshyperedge.h"
 
33
 
 
34
/// lists of objects of arbitrary type T.
 
35
template <class T> class Bag  {
 
36
/*@Doc: {\large {\bf scope:} global} */
 
37
public:
 
38
        /// create an empty list.
 
39
        Bag(); 
 
40
        ///
 
41
        Bag (const List<T> &l, int n);
 
42
        ///
 
43
        Bag (const Bag <T> &b);
 
44
        /// add e to bag
 
45
        void add(const T &e);
 
46
 
 
47
        /// add e to n times to bag
 
48
        void add(const T &e, int n);
 
49
 
 
50
        /// insert e to i+1'th position of the list. 
 
51
        //      void insert(const T &e, const unsigned i); 
 
52
 
 
53
        /// return index of first element equal to e, if not found, return -1.
 
54
        //      int find(const T &e) const;     
 
55
 
 
56
        /// return list is set                                         
 
57
        bool isSet() const;                                             
 
58
 
 
59
        /// count the number of times e occurs in the list
 
60
        int count(const T &e) const;                                   
 
61
 
 
62
        int length(void);
 
63
 
 
64
        /// return if bag contains bag l                            
 
65
        bool contains(Bag<T> &l) const;                               
 
66
 
 
67
        void join(const Bag <T> &l);
 
68
 
 
69
        // difference
 
70
        bool diff( Bag <T> &l);
 
71
 
 
72
        // get all elements (including those that might not be in the bag)
 
73
        void GetList(List<T> &l) const {l=list;};
 
74
 
 
75
        /// get all elements that occur more than once and put them in set
 
76
        void GetSet(List<T> *l);
 
77
 
 
78
        bool remove(const T &e);
 
79
 
 
80
        void empty();
 
81
private:
 
82
        ///
 
83
        List <T> list ;
 
84
        /// list[i] is countl[i] times in the bag
 
85
        int countl[MAXLENGTH];  
 
86
};
 
87
 
 
88
 
 
89
#endif