This site contains older material on Eiffel. For the main Eiffel page, see http://www.eiffel.com.

EiffelBase class
(HTML page generated by ISE Eiffel 4.2)

Eiffel Class
indexing
	description: "Sets implemented by linked lists";
	status: "See notice at end of class";
	names: linked_set, set, linked_list;
	representation: linked;
	access: membership;
	contents: generic;
	date: "$Date: 2007-03-30 19:10:11 +0000 (Fri, 30 Mar 2007) $";
	revision: "$Revision: 95354 $"

class LINKED_SET [G]

inherit
	SUBSET [G]
		undefine
			prune_all
		select
			extend, put, prune
		end;
	LINKED_LIST [G]
		rename
			extend as ll_extend,
			put as ll_put,
			prune as ll_prune
		export
			{NONE} ll_extend, ll_put, ll_prune
		undefine
			changeable_comparison_criterion
		end

creation
	make

feature -- Comparison

	is_subset (other: like Current): BOOLEAN is
			-- Is current set a subset of other?
		do
			if notother.empty and then count <= other.count then
				from
					start
				until
					off or else notother.has (item)
				loop
					forth
				end;
				if off then
					Result := true
				end
			elseif empty then
				Result := true
			end
		end;

feature -- Element change

	put (v: G) is
			-- Ensure that set includes v.
			-- Was declared in LINKED_SET as synonym of put and extend.
		do
			if empty or else nothas (v) then
				put_front (v)
			end
		end;

	extend (v: G) is
			-- Ensure that set includes v.
			-- Was declared in LINKED_SET as synonym of put and extend.
		do
			if empty or else nothas (v) then
				put_front (v)
			end
		end;

	merge (other: like Current) is
			-- Add all items of other.
		do
			from
				other.start
			until
				other.off
			loop
				extend (other.item);
				other.forth
			end
		end;

feature -- Removal

	prune (v: like item) is
			-- Remove v if present.
		do
			start;
			ll_prune (v)
		end;

feature -- Basic operations

	intersect (other: like Current) is
			-- Remove all items not in other.
			-- No effect if other is empty.
		do
			if notother.empty then
				from
					start;
					other.start
				until
					off
				loop
					if other.has (item) then
						forth
					else
						remove
					end
				end
			else
				wipe_out
			end
		end;

	subtract (other: like Current) is
			-- Remove all items also in other.
		do
			if not(other.empty or empty) then
				from
					start;
					other.start
				until
					off
				loop
					if other.has (item) then
						remove
					else
						forth
					end
				end
			end
		end;

end -- class LINKED_SET