edges.sa


Generated by gen_html_sa_files from ICSI. Contact gomes@icsi.berkeley.edu for details
 
---------------------------> Sather 1.1 source file <--------------------------
-- Edges for the graph classes
-- Author: Benedict A. Gomes <gomes@tiramisu.ICSI.Berkeley.EDU>
-- Copyright (C) 1995, International Computer Science Institute
-- COPYRIGHT NOTICE: This code is provided WITHOUT ANY WARRANTY
-- and is subject to the terms of the SATHER LIBRARY GENERAL PUBLIC
-- LICENSE contained in the file: Sather/Doc/License of the
-- Sather distribution. The license is also available from ICSI,
-- 1947 Center St., Suite 600, Berkeley CA 94704, USA.


abstract class $EDGE{NTP} < $STR

abstract class $EDGE{NTP} < $STR is first: NTP; second: NTP; end;

class UEDGE{NTP} < $EDGE{NTP}, $HASH

class UEDGE{NTP} < $EDGE{NTP}, $HASH is -- Undirected edge include COMPARABLE; private include COMPARE{NTP}; readonly attr first, second: NTP; create(f,s: NTP): SAME is res ::= new; res.first := f; res.second := s; return res; --res: SAME; return(res.first(f).second(s)); end; is_eq(e:UEDGE{NTP}): BOOL is return (elt_eq(first,e.first) and elt_eq(second, e.second)) or (elt_eq(first,e.second) and elt_eq(second, e.first)) end; is_reflexive: BOOL is return elt_eq(first,second);end; hash:INT is -- A simple hash value computed from the hash values of the -- components. For this to work, these must either be value -- types which define hash values or reference types. h1,h2:INT; h1 := elt_hash(first); h2 := elt_hash(second); return h1.bxor(h2.lshift(2)) end; str: STR is return "{"+elt_str(first)+","+elt_str(second)+"}"; end; elt_str(e: NTP): STR is typecase e when $STR then return e.str else return "first" end; end; end;

class DIEDGE{NTP} < $EDGE{NTP}, $HASH

class DIEDGE{NTP} < $EDGE{NTP}, $HASH is -- Directed edge include COMPARABLE; include COMPARE{NTP}; readonly attr first, second: NTP; create(f,s: NTP): SAME is res ::= new; res.first := f; res.second := s; return res; -- res: SAME; -- return(res.first(f).second(s)); end; reverse: DIEDGE{NTP} is return #(second,first); end; is_reflexive: BOOL is return elt_eq(first, second) end; is_eq(e:DIEDGE{NTP}): BOOL is return ((elt_eq(first,e.first) and elt_eq(second,e.second))) end; hash:INT is -- A simple hash value computed from the hash values of the -- components. For this to work, these must either be value -- types which define hash values or reference types. h1,h2:INT; h1 := elt_hash(first); h2 := elt_hash(second); return h1.bxor(h2.lshift(2)) end; str: STR is return "{"+elt_str(first)+","+elt_str(second)+"}"; end; elt_str(e: NTP): STR is typecase e when $STR then return e.str else return "first" end; end; end;