aboutsummaryrefslogtreecommitdiff
path: root/scripts/resource-set.py
blob: 49b6fc9b426bb907b87305272fe64a6d94b6f2da (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# $Id$

class resource(object):

  def __init__(self, car, cdr):
    self.car = car
    self.cdr = cdr

  def __str__(self):
    return "(" + str(self.car) + " . " + str(self.cdr) + ")"

  def __eq__(self, other):
    return self.car == other.car and self.cdr == other.cdr

  def __hash__(self):
    return self.car.__hash__() + self.cdr.__hash__()

class resource_set(set):

  def __init__(self, *elts):
    for e in elts:
      assert isinstance(e, resource)
    set.__init__(self, elts)

  def __str__(self):
    return "(" + " ".join(map(str, self)) + ")"

s = resource_set(resource("a", "b"), resource("c", "d"), resource("a", "b"))

print s

print len(s)

for i in s:
  print i