set.cpp revision 3863
196N/A * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. 0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 0N/A * This code is free software; you can redistribute it and/or modify it 0N/A * under the terms of the GNU General Public License version 2 only, as 0N/A * published by the Free Software Foundation. 0N/A * This code is distributed in the hope that it will be useful, but WITHOUT 0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 0N/A * version 2 for more details (a copy is included in the LICENSE file that 0N/A * accompanied this code). 0N/A * You should have received a copy of the GNU General Public License version 0N/A * 2 along with this work; if not, write to the Free Software Foundation, 0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 0N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 113N/A// Sets - An Abstract Data Type 0N/A// %%%%% includes not needed with AVM framework - Ungar 0N/A// Not needed and it causes terouble for gcc. 0N/A//-------------------------Virtual Functions----------------------------------- 0N/A// These functions MUST be implemented by the inheriting class. 0N/A/* Removed for MCC BUG 0N/A Set::operator const SparseSet*() const { assert(0); return NULL; } */ 0N/A/* Removed for MCC BUG 0N/A Set::operator const VectorSet*() const { assert(0); return NULL; } */ 0N/A/* Removed for MCC BUG 0N/A Set::operator const ListSet*() const { assert(0); return NULL; } */ 0N/A/* Removed for MCC BUG 0N/A Set::operator const CoSet*() const { assert(0); return NULL; } */ 0N/A//------------------------------setstr----------------------------------------- 0N/A// Create a string with a printable representation of a set. 0N/A// The caller must deallocate the string. 0N/A set.
Sort();
// Sort elements for in-order retrieval 0N/A register char *s =
buf;
// Current working string pointer 0N/A // For all elements of the Set 0N/A if(
hi+
1 == i.
elem ) {
// Moving sequentially thru range? 0N/A hi = i.
elem;
// Yes, just update hi end of range 0N/A }
else {
// Else range ended 0N/A if(
buf+
len-s <
25 ) {
// Generous trailing space for upcoming numbers 0N/A int offset = (
int)(s-
buf);
// Not enuf space; compute offset into buffer 0N/A len <<=
1;
// Double string size 0N/A s =
buf+
offset;
// Get working pointer into new bigger buffer 0N/A if(
lo != (
uint)-
2 ) {
// Startup? No! Then print previous range. 0N/A if(
buf+
len-s <
25 ) {
// Generous trailing space for upcoming numbers 0N/A int offset = (
int)(s-
buf);
// Not enuf space; compute offset into buffer 0N/A len <<=
1;
// Double string size 0N/A s =
buf+
offset;
// Get working pointer into new bigger buffer 0N/A // Don't delete the clone 'set' since it is allocated on Arena. 0N/A//------------------------------print------------------------------------------ 0N/A// Handier print routine 0N/A//------------------------------parse------------------------------------------ 0N/A// Convert a textual representation of a Set, to a Set and union into "this" 0N/A// Set. Return the amount of text parsed in "len", or zero in "len". 0N/A register char c;
// Parse character 0N/A register const char *t = s;
// Save the starting position of s. 0N/A do c = *s++;
// Skip characters 0N/A while( c && (c <=
' ') );
// Till no more whitespace or EOS 0N/A if( c !=
'{' )
return 0;
// Oops, not a Set openner 0N/A if( *s ==
'}' )
return 2;
// The empty Set 0N/A // Sets are filled with values of the form "xx," or "xx-yy," with the comma 0N/A // a "}" at the very end. 0N/A while(
1 ) {
// While have elements in the Set 0N/A char *u;
// Pointer to character ending parse 0N/A uint hi, i;
// Needed for range handling below 0N/A if( u == s )
return 0;
// Bogus crude 0N/A s = u;
// Skip over the number 0N/A c = *s++;
// Get the number seperator 0N/A switch ( c ) {
// Different seperators 0N/A case '}':
// Last simple element 0N/A case ',':
// Simple element 342N/A (*
this) <<=
elem;
// Insert the simple element into the Set 342N/A break;
// Go get next element 342N/A if( u == s )
return 0;
// Bogus crude 342N/A (*
this) <<= i;
// Insert the entire range into the Set 342N/A s = u;
// Skip over the number 0N/A c = *s++;
// Get the number seperator 0N/A if( c ==
'}' )
break;
// End of the Set 0N/A if( c !=
',' )
return 0;
// Bogus garbage 0N/A return (
int)(s-t);
// Return length parsed 0N/A//------------------------------Iterator---------------------------------------