~ubuntu-branches/ubuntu/utopic/tcm/utopic

« back to all changes in this revision

Viewing changes to src/sd/bv/hashlist.c

  • 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
#define HASHSIZE 100003
 
24
 
 
25
#include "hashlist.h"
 
26
#include "adsvaluation.h"
 
27
#include "adstransition.h"
 
28
#include <stdlib.h>
 
29
 
 
30
ValuationHashList::ValuationHashList() {
 
31
  int i;
 
32
  for (i = 0; i < HASHSIZE; i++) {
 
33
    hash_list.add(NULL);
 
34
  }
 
35
}
 
36
 
 
37
void ValuationHashList::add(ADSValuation *adk,int key) {
 
38
  key=key % HASHSIZE;
 
39
  if (!hash_list[key]) hash_list[key]=new List<ADSValuation *> ;
 
40
  hash_list[key]->add(adk);
 
41
}
 
42
 
 
43
ADSValuation *ValuationHashList::isin(ADSValuation *adk,int key) {
 
44
  key=key % HASHSIZE;
 
45
  List <ADSValuation *> *l=hash_list[key];
 
46
  if (!l)  return NULL;   
 
47
  for (l->first();!l->done();l->next()){
 
48
    if (*(l->cur())==*adk) return l->cur();
 
49
  }
 
50
  return NULL;
 
51
}
 
52
 
 
53
/*
 
54
void ValuationHashList::Write(OutputFile *f){
 
55
  int i,j;
 
56
  j=0;
 
57
  for (i = 0; i < HASHSIZE; i++) {
 
58
    (*f) << "entry:\t"<< i << "\t\tused:\t"<<  (hash_list[i]==NULL?0:hash_list[i]->count() ) << "\n" ;
 
59
    if (hash_list[i]!=NULL) j=j+hash_list[i]->count();
 
60
  }
 
61
  (*f) << "\nTotal:\t"<< j <<"\n\n\n\n";
 
62
}
 
63
*/
 
64
 
 
65
TransitionHashList::TransitionHashList() {
 
66
  int i;
 
67
  for (i = 0; i < HASHSIZE; i++) {
 
68
    hash_list.add(NULL);
 
69
  }
 
70
}
 
71
 
 
72
void TransitionHashList::add(ADSTransition *t,int key) {
 
73
  key=key % HASHSIZE;
 
74
  if (!hash_list[key]) hash_list[key]=new List<ADSTransition *> ;
 
75
  hash_list[key]->add(t);
 
76
}
 
77
 
 
78
ADSTransition *TransitionHashList::isin(ADSTransition *t,int key) {
 
79
  key=key % HASHSIZE;
 
80
  List <ADSTransition *> *l=hash_list[key];
 
81
  if (!l)  return NULL;   
 
82
  for (l->first();!l->done();l->next()){
 
83
    if (*(l->cur())==*t) return l->cur();
 
84
  }
 
85
  return NULL;
 
86
}
 
87
 
 
88
/*
 
89
void TransitionHashList::Write(OutputFile *f){
 
90
  int i;
 
91
  for (i = 0; i < HASHSIZE; i++) {
 
92
    (*f) << "entry:\t"<< i << "\t\tused:\t"<<  (hash_list[i]==NULL?0:hash_list[i]->count() ) << "\n" ;
 
93
  }
 
94
}
 
95
*/
 
96