      *>----------------------------------------------------------------
      *> An instance of ValueSet is a collection of
      *> non-ordered objects or intrinsics. Duplicates are not allowed
      *> in a ValueSet. The ValueSet class tests for duplicates by
      *> sending elements the "equal" message.
      *>
      *> Elements are only compared with the "equal" message if they
      *> have the same hash value. Objects return hash values when you
      *> send them the "hash" message. You should override the default
      *> implementation of "hash" in the Base class anytime that you
      *> override the default implementation of "equal". The defaults
      *> are based on object handles, not on their contents.
      *>
      *>#See class "iset".
      *>
      *> Copyright (C) 1991-1999 Micro Focus International Ltd.
      *>
      *>----------------------------------------------------------------
      $set localcount(200) linkcount(150) mfoo
       class-id. ValueSet data is protected
               inherits from collection with data.


        object section.
        class-control.
           collection is class "collectn"
           ValueSet is class "valueset"
           callback is class "callback".

       class-object.

       object-storage section.
      *>---------------------------------------------------------------
      *> PRIVATE. Method to create a ValueSet of any type.
      *>---------------------------------------------------------------
       method-id. "privatenew".
       local-storage section.
       01 newsize          pic s9(9) comp-5.
       01 lsTemp           pic s9(9) comp-5.

       linkage section.
       01 lnksize              pic s9(9) comp-5.
       01 lnkstride             pic s9(9) comp-5.
       01 acollection          usage object reference.
       01 lnktemplate          usage object reference.

       procedure division using lnksize lnktemplate lnkstride
                             returning acollection.
           invoke super "new" returning acollection
           invoke acollection "initialize" using lnksize
                                                 lnktemplate
                                                 lnkstride
           exit method.
       end method "privatenew".

      *>---------------------------------------------------------------
      *> Return a new instance of ValueSet with a capability of holding
      *> lnkSize intrinsics of type defined by the class aTemplate.
      *>---------------------------------------------------------------
       method-id. "ofValues".
       local-storage section.
       01 astride              pic s9(9) comp-5.
       01 lssize               pic s9(9) comp-5.
       linkage section.
       01 lnktemplate          usage object reference.
       01 lnksize              pic s9(9) comp-5.
       01 acollection          usage object reference.

       procedure division using lnktemplate lnksize
                                            returning acollection.
           if lnksize < zero
               invoke self "invalidParameter" returning acollection
           else
               if lnksize = zero
                   move 1 to lssize
               else
                   move lnksize to lssize
               end-if
               invoke lnktemplate "sizeInBytes" returning astride
               invoke self "privateNew" using lssize
                                               lnktemplate
                                               astride
                                     returning acollection
           end-if
           exit method.
       end method "ofValues".
      *>----------------------------------------------------------------
      *> Return a new instance of ValueSet capable of holding lnkSize
      *> objects.
      *>----------------------------------------------------------------
       method-id. "ofReferences".
       local-storage section.
       01 astride              pic s9(9) comp-5.
       01 anObject             usage object reference.
       01 lssize               pic s9(9) comp-5.
       linkage section.
       01 lnksize              pic s9(9) comp-5.
       01 acollection          usage object reference.

       procedure division using lnksize returning acollection.
           if lnksize < zero
               invoke self "invalidParameter" returning acollection
           else
               if lnksize = zero
                   move 1 to lssize
               else
                   move lnksize to lssize
               end-if
               move objectReferenceSize to astride
               set anObject to null
               invoke self "privateNew" using lssize anObject astride
                                         returning acollection
           end-if
           exit method.
       end method "ofReferences".

       end class-object.

       Object.

       object-storage section.

      *>>---------------------------------------------------------------
      *>> The total number of bytes required to store the empty flags
      *>>---------------------------------------------------------------

       01 emptybits pic x(4) comp-5 value 0.

      *>>---------------------------------------------------------------
      *>> The capacity (measured in objects being stored) that this
      *>> set is capable of holding.
      *>>---------------------------------------------------------------

       01 capacity  pic x(4) comp-5 value 0.
      *>---------------------------------------------------------------
      *> PRIVATE method used to initialize instance variables for new
      *> ValueSet's
      *>---------------------------------------------------------------
       method-id. "initialize".
       local-storage section.
       01 lssize               pic s9(9) comp-5.

       linkage section.
       01 lnkSize              pic s9(9) comp-5.
       01 lnkStride            pic s9(9) comp-5.
       01 lnkTemplate          usage object reference.


       procedure division using lnkSize lnkTemplate lnkStride.
           move lnkSize to storagerequirements numberelements
           move lnkStride to collectionstride
           multiply lnkStride by storagerequirements
           set collectiontemplate to lnkTemplate
           add 1 to storagerequirements giving lsSize
           divide 8 into lnkSize giving emptybits
           add 1 to emptybits
           add emptybits to lsSize
           invoke self "malloc" using lsSize
                        returning collPtr

           move zero to numberelements
           move storagerequirements to capacity
           divide collectionstride into capacity
           exit method.
       end method "initialize".

      *>----------------------------------------------------------------
      *> PRIVATE. Returns the element at the real index position
      *> anIndex. If anIndex is out of bounds an exception is raised.
      *>----------------------------------------------------------------
       method-id. "privateat".
       local-storage section.
       01 realindex            pic s9(9) comp-5.

       linkage section.
       01 anindex              pic s9(9) comp-5.
       01 anelement2           COLLECTABLE.
       01 instanceData         pic x.
       procedure division using anindex returning anelement2.
           if anindex < 1 or anindex > capacity
               invoke self "errorInBounds" returning anelement2
           else
               compute realindex = (anindex - 1) * collectionstride + 1
               set address of instancedata to collptr

      $if GC defined
               if collectionTemplate = null
                   call "oopsassignobjectreference" using
                       by reference anelement2(1:objectreferencesize)
                       by value
                            instancedata(realindex:objectreferencesize)
               else
                   if Storingobjects
                       invoke instancedata(realindex : collectionstride)
                         as collectionTemplate "getValue"
                         returning anelement2(1:collectionStride)
                   else
                       move instancedata(realindex:collectionstride) to
                                anelement2(1:collectionStride)
                   end-if

               end-if
      $else
               move instancedata(realindex:collectionstride) to
                   anelement2(1:collectionStride)
      $end  
           end-if
           exit method
       end method "privateat".

      *>----------------------------------------------------------------
      *> PRIVATE. Returns true if anElement is at the real index
      *> position anIndex otherwise returns false.
      *>----------------------------------------------------------------
       method-id. "isat".
       local-storage section.
       01 aptr             pointer.

       linkage section.
       01 anindex              pic s9(9) comp-5.
       01 lnkbool                 pic x comp-5.
           88 lnkistrue           value 1.
           88 lnkisfalse          value 0.
       01 anelement2            COLLECTABLE.
       01 anelement             COLLECTABLE.

       procedure division using anelement anindex
                          returning lnkbool.
           invoke self "isOccuppiedAt" using anindex
                                        returning lnkbool
           if lnkistrue
               invoke self "allocateElement" returning aptr
               set address of anelement2 to aptr

               invoke self "basicAtNoGC"
                        using anindex returning anElement2
               if collectiontemplate equal to null
                   invoke anelement2 as object "equal" using anelement
                                  returning lnkbool
               else
                   if anelement2(1:collectionStride)
                                = anelement(1:collectionStride)
                       set lnkistrue to true
                   else
                       set lnkisfalse to true
                   end-if
               end-if
               invoke self "dealloc" using aptr
           end-if
           exit method.
       end method "isat".

      *>----------------------------------------------------------------
      *> Return the number of elements within this ValueSet.
      *>----------------------------------------------------------------
       method-id. "size".
       linkage section.
       01 acollectionsize      pic s9(9) comp-5.

       procedure division returning acollectionsize.
           move numberelements to acollectionsize
           exit method.
       end method "size".
      *>----------------------------------------------------------------
      *> Return true if this set contains anElement, otherwise return
      *> false.
      *>----------------------------------------------------------------
       method-id. "includes".
       local-storage section.
       01 i                    pic s9(9) comp-5.

       linkage section.
       01 anelement            COLLECTABLE.
       01 lnkbool                 pic x comp-5.
           88 lnkistrue           value 1.
           88 lnkisfalse          value 0.

       procedure division using anelement returning lnkbool.
           invoke self "findElement" using anelement
                                      returning i
           invoke self "isOccuppiedAt" using i returning lnkbool
           exit method.
       end method "includes".
      *>----------------------------------------------------------------
      *> Return the number of elements anElement is equal to. The
      *> result of this is either one or zero because two equal elements
      *> cannot be stored in a set.
      *>----------------------------------------------------------------
       method-id. "occurrencesOf".
       local-storage section.
       01 bool                 pic x comp-5.
           88 istrue           value 1.
           88 isfalse          value 0.

       linkage section.
       01 anumber              pic s9(9) comp-5.
       01 anelement            COLLECTABLE.

       procedure division using anelement returning anumber.
           invoke self "includes" using anelement
                                   returning bool
           if istrue
               move 1 to anumber
           else
               move zero to anumber
           end-if
           exit method.
       end method "occurrencesOf".
      *>----------------------------------------------------------------
      *> Return the number of elements this collection is capable of
      *> holding.
      *>----------------------------------------------------------------
       method-id. "capacity".
       linkage section.
       01 acollectionsize      pic s9(9) comp-5.

       procedure division returning acollectionsize.
           move capacity to acollectionsize
           exit method.
       end method "capacity".
      *>----------------------------------------------------------------
      *> Cause this ValueSet collection to become larger in order
      *> to store more members.
      *>----------------------------------------------------------------
       method-id. "grow".
       local-storage section.
       01 anewset              usage object reference.
       01 exceptionnumber      pic s9(9) comp-5.
       01 bool                 pic x comp-5.
          88 istrue           value 1.
          88 isfalse          value 0.
       01 oldsize              pic s9(9) comp-5.
       01 anobject         usage object reference.
       01 asize                pic s9(9) comp-5.
       01 newsize          pic s9(9) comp-5.

       procedure division.
           invoke self "copy" returning anewset
           move capacity to oldsize
           add 5 to oldsize giving asize
           multiply 2 by asize
           move asize to storagerequirements capacity
           multiply collectionstride by storagerequirements

           *>> compute emptybits = (asize / 8) + 1

           divide 8 into asize giving emptybits
           add 1 to emptybits
           add emptybits to storagerequirements giving newsize

           invoke self "dealloc" using collptr
           invoke self "malloc" using newsize returning collptr
           if collptr not = null
                invoke self "replaceContentsWith" using anewset
                invoke anewset "finalize" returning anobject
           else
               move 32 to exceptionNumber
               invoke self "raiseException" using exceptionNumber                
           end-if
           exit method.
       end method "grow".

      *>----------------------------------------------------------------
      *> PRIVATE. Causes the whole contents of the receiver to be
      *> replaced with the contents of aCollection. The only use
      *> of this method is to perform rehashing after a grow.
      *>----------------------------------------------------------------
       method-id. "replaceContentsWith".
       local-storage section.
       01 amessageselector pic x(80).
       01 amessage2            usage object reference.

       linkage section.
       01 acollection          usage object reference.
       01 instanceData         pic x.
       procedure division using acollection.
           set address of instanceData to collptr
      $if GC defined
           invoke self "decreaseReferences"
      $end
           move low-values to
                instancedata(1:storagerequirements + emptybits)
           move zero to numberelements
           move "add" to amessageselector
           invoke callback "new" using self amessageselector
                                    returning amessage2
           invoke acollection "doWithOutCopy" using amessage2
           invoke amessage2 "finalize" returning amessage2
           exit method.
       end method "replaceContentsWith".
      *>----------------------------------------------------------------
      *> Return a new set containing the members of this set
      *> concatenated with the members of aCollection.
      *>----------------------------------------------------------------
       method-id. "concat".
       local-storage section.
       01 bool                 pic x comp-5.
           88 istrue           value 1.
           88 isfalse          value 0.

       linkage section.
       01 anewcollection       usage object reference.
       01 acollection          usage object reference.

       procedure division using acollection
                            returning anewcollection.
           invoke self "isCompatible" using acollection
                                       returning bool
           if istrue
               invoke self "copy" returning anewcollection
               invoke anewcollection "addAll" using acollection
           else
               invoke self "compatibilityError"
                       returning aNewCollection
           end-if
           exit method.
       end method "concat".
      *>----------------------------------------------------------------
      *> Iterate over the members of the set sending aMessage for each
      *> element, passing that element as a parameter.
      *> aMessage should be a CallBack pointing to a method which
      *> expects an element as a parameter.
      *> For more information see the topic Collection Iterator Methods
      *> in the on-line documentation.
      *>----------------------------------------------------------------
       method-id. "doWithOutCopy".
       local-storage section.
       01 ooreturnptr          usage pointer.
       01 bool                 pic x comp-5.
          88 istrue           value 1.
          88 isfalse          value 0.
       01 j                    pic s9(9) comp-5.
       01 i                    pic s9(9) comp-5.
       01 thissize             pic s9(9) comp-5.

       linkage section.
       01 anelement            COLLECTABLE.
       01 amessage             usage object reference.
       procedure division using amessage.
           invoke self "size" returning thissize
           set oonoquit to true

           invoke self "allocateElement" returning ooreturnptr
           move zero to i
           set address of anelement to ooreturnPtr
           perform varying j from 1 by 1 until i = thissize or ooquit
               invoke self "isEmptyAt" using j returning bool
               if isfalse
                   invoke self "basicAt" using j returning anElement
                   invoke amessage "invoke" using anElement
                   add 1 to i
               end-if
           end-perform
      $if gc defined
           if collectionTemplate = null
                call "oopsrelease" using
                        by value 1
                        by value anElement(1:objectreferencesize)
           else
                if storingObjects
                    invoke anElement(1:collectionStride) AS
                                 collectionTemplate "decreaseReferences"
                end-if

           end-if
      $end
           set oonoquit to true
           invoke self "dealloc" using ooreturnptr
           exit method.
       end method "doWithOutCopy".
      *>----------------------------------------------------------------
      *> Send aMessage for each element of this value set in turn,
      *> passing that element as a parameter.
      *> aMessage should be a CallBack pointing to a method which
      *> expects an element as a parameter.
      *> For more information see the topic Collection Iterator Methods
      *> in the on-line documentation.
      *>----------------------------------------------------------------
       method-id. "do".
       local-storage section.
       01 ooreturnptr          usage pointer.
       01 bool                 pic x comp-5.
          88 istrue           value 1.
          88 isfalse          value 0.
       01 j                    pic s9(9) comp-5.
       01 i                    pic s9(9) comp-5.
       01 thissize             pic s9(9) comp-5.
       01 aCopy                usage object reference.

       linkage section.
       01 anelement            COLLECTABLE.
       01 amessage             usage object reference.
       procedure division using amessage.
           invoke self "size" returning thissize
           set oonoquit to true

           invoke self "allocateElement" returning ooreturnptr
           move zero to i
           set address of anelement to ooreturnPtr
           invoke self "copy" returning aCopy
           perform varying j from 1 by 1 until i = thissize or ooquit
               invoke aCopy "isEmptyAt" using j returning bool
               if isfalse
                   invoke aCopy "basicAt" using j returning anElement
                   invoke amessage "invoke" using anElement
                   add 1 to i
               end-if
           end-perform
      $if gc defined
           if collectionTemplate = null
                call "oopsrelease" using
                        by value 1
                        by value anElement(1:objectreferencesize)
           else
                if storingObjects
                    invoke anElement(1:collectionStride) AS
                                 collectionTemplate "decreaseReferences"
                end-if

           end-if
      $end

           invoke aCopy "finalize" returning aCopy
           set oonoquit to true
           invoke self "dealloc" using ooreturnptr
           exit method.
       end method "do".
      *>----------------------------------------------------------------
      *> Behaves exactly as the method "do" as ValueSet does not store
      *> elements in any predefined order.
      *>----------------------------------------------------------------
       method-id. "reverseDo".
       linkage section.
       01 amessage             usage object reference.

       procedure division using amessage.
           invoke self "do" using amessage
           exit method.
       end method "reverseDo".

      *>---------------------------------------------------------------
      *> PRIVATE. Return address of element at position anIndex
      *>---------------------------------------------------------------
       method-id. "basicAt".
       local-storage section.
       01 realindex           pic s9(9) comp-5.
       01 anAddress           usage pointer.
       linkage section.
       01 anindex              pic s9(9) comp-5.
       01 anElement           COLLECTABLE.
       01 anElement2          COLLECTABLE.

       procedure division using anindex returning anElement.
           subtract 1 from anIndex giving realIndex
           multiply collectionStride by realIndex

           set anaddress to collptr
           set anaddress up by realindex
           set address of anElement2 to anAddress
      $if gc defined
           if collectionTemplate = null
               call "oopsassignobjectreference"
                  using by reference anElement(1:objectreferencesize)
                        by value anElement2(1:objectreferencesize)
           else
               if Storingobjects
                   invoke anElement2(1:collectionStride)
                         as collectionTemplate "getValue"
                         returning anElement(1:collectionStride)
               else
                   move anElement2(1:collectionStride)
                        to anElement(1:collectionStride)
               end-if
           end-if
      $else
           move anElement2(1:collectionStride)
                        to anElement(1:collectionStride)

      $end
           exit method.
       end method "basicAt".

      *>---------------------------------------------------------------
      *> PRIVATE. Return address of element at position anIndex
      *>---------------------------------------------------------------
       method-id. "basicAtNoGC".
       local-storage section.
       01 realindex           pic s9(9) comp-5.
       01 anAddress           usage pointer.
       linkage section.
       01 anindex              pic s9(9) comp-5.
       01 anElement           COLLECTABLE.
       01 anElement2          COLLECTABLE.

       procedure division using anindex returning anElement.
           subtract 1 from anIndex giving realIndex
           multiply collectionStride by realIndex

           set anaddress to collptr
           set anaddress up by realindex
           set address of anElement2 to anAddress
           move anElement2(1:collectionStride)
                        to anElement(1:collectionStride)
           exit method.
       end method "basicAtNoGC".

      *>---------------------------------------------------------------
      *> PRIVATE. Returns the index of the anElement or an index for
      *> where anElement can be stored if it doesn't exist
      *>---------------------------------------------------------------
       method-id. "findElement".
       local-storage section.
       01 temp                 pic s9(9) comp-5.
       01 bool                 pic x comp-5.
          88 istrue           value 1.
          88 isfalse          value 0.
       01 asize                pic s9(9) comp-5.
       01 hashvalue            pic s9(9) comp-5.

       linkage section.
       01 anindex              pic s9(9) comp-5.
       01 anelement            COLLECTABLE.

       procedure division using anelement returning anindex.
           move capacity to asize
           if collectiontemplate equal to null
               invoke anelement as object
                   "hash" returning hashvalue
           else
               invoke anelement as collectiontemplate
                               "hash" returning hashvalue
           end-if
           move hashvalue to anindex
           set isfalse to true
           perform with test after until istrue
               divide anindex by asize giving temp
                                      remainder anindex
               add 1 to anindex
               invoke self "isEmptyAt" using anindex returning bool
               if isfalse
                   invoke self "isAt" using anelement anindex
                                   returning bool
               end-if
           end-perform
           exit method.
       end method "findElement".

      *>---------------------------------------------------------------
      *> Add anElement to this ValueSet. If you attempt to add a
      *> duplicate element, it is ignored.
      *>---------------------------------------------------------------
       method-id. "add".
       local-storage section.
       01 realindex            pic s9(9) comp-5.
       01 i                    pic s9(9) comp-5.
       01 bool                 pic x comp-5.
          88 istrue            value 1.
          88 isfalse           value 0.
       01 growthLimit         pic x(4) comp-5.

       linkage section.
       01 anelement            COLLECTABLE.
       01 instancedata         pic x.

       procedure division using anelement.
           multiply capacity by 7 giving growthLimit
           divide 10 into growthLimit
           if growthLimit <= numberelements
               invoke self "grow"
           end-if
           invoke self "findELement" using anelement returning i
           invoke self "isEmptyAt" using i returning bool
           if istrue
               compute realindex = (i - 1) * collectionstride + 1
               set address of instanceData to collptr
      $if GC defined
               if collectionTemplate = null
                   call "oopsassignobjectreference" using
                   by reference
                        instancedata(realindex:objectreferencesize)
                   by value anelement(1:objectreferencesize)
               else
                   if Storingobjects
                        invoke anelement(1:collectionStride)
                         as collectionTemplate "getValue" returning
                         instancedata(realindex:collectionstride)
                   else

                        move anelement(1:collectionStride) to
                         instancedata(realindex:collectionstride)
                   end-if
               end-if
      $else
               move anelement(1:collectionStride) to
                   instancedata(realindex:collectionstride)

      $end
               invoke self "setOccuppied" using i
               add 1 to numberelements
           end-if
           exit method.
       end method "add".
      *>---------------------------------------------------------------
      *>    Remove anElement from this ValueSet's members. If anElement
      *> does not exist then raise an exception. Return the element
      *> that has been removed.
      *>---------------------------------------------------------------
       method-id. "remove".
       local-storage section.
       01 lsPtr                pointer.
       01 realindex            pic s9(9) comp-5.
       01 exceptionnumber  pic s9(9) comp-5.
       01 bool                 pic x comp-5.
          88 istrue           value 1.
          88 isfalse          value 0.
       01 i                    pic s9(9) comp-5.

       linkage section.
       01 anelement            COLLECTABLE.
       01 instanceData         pic x.

       procedure division using anelement.
           invoke self "findElement" using anelement returning i
           invoke self "isOccuppiedAt" using i returning bool
           if isfalse
               move 12 to exceptionnumber
               invoke self "raiseException" using exceptionnumber
           else
               compute realindex = (i - 1) * collectionstride + 1
               set address of instanceData to collptr

      $if GC defined
               if collectionTemplate = null
                   call "oopsassignobjectreference" using
                   by reference
                           instancedata(realindex:objectreferencesize)
                   by value 0
               else
                   if Storingobjects
                        invoke self "allocateElement" returning lsPtr
                        set address of anElement to lsPtr
                        invoke anelement(1:collectionStride)
                         as collectionTemplate "getValue" returning
                         instancedata(realindex:collectionstride)
                        invoke self "dealloc" using lsptr
                   else
                        move low-values to
                           instancedata(realindex:collectionstride)
                   end-if
               end-if
      $else
               move low-values to
                      instancedata(realindex:collectionstride)

      $end
               subtract 1 from numberelements
               invoke self "setEmpty" using i
               invoke self "fixCollisionsFrom" using i
           end-if
           exit method.
       end method "remove".
      *>---------------------------------------------------------------
      *> PRIVATE. Fixes all the collisions after an element has been
      *> removed.
      *>---------------------------------------------------------------
       method-id. "fixCollisionsFrom".
       local-storage section.
       01 temp                 pic s9(9) comp-5.
       01 realindex            pic s9(9) comp-5.
       01 bool                 pic x comp-5.
          88 istrue           value 1.
          88 isfalse          value 0.
       01 aptr                 pointer.
       01 j                    pic s9(9) comp-5.
       01 i                    pic s9(9) comp-5.
       01 asize                pic s9(9) comp-5.

       linkage section.
       01 anindex              pic s9(9) comp-5.
       01 anelement            COLLECTABLE.
       01 instanceData         pic x.

       procedure division using anindex.
                *>> Should not need to add GC calls as this method
                *>> only move o-r's around and does not create
                *>> any new references.

           move capacity to asize
           divide anindex by asize giving temp remainder i
           add 1 to i
           invoke self "isEmptyat" using i returning bool
           invoke self "allocateElement" returning aptr
           set address of anelement to aptr
           perform until istrue
               invoke self "basicatNoGC" using i returning anElement
               invoke self "findElement" using anelement returning j
               if j not = i
                   set address of instanceData to collptr
                   compute realindex = (j - 1) * collectionstride + 1                                       
                   move anelement(1:collectionStride) to
                           instancedata (realindex:collectionstride)
                   invoke self "setoccuppied" using j
                   compute realindex = (i - 1) * collectionstride + 1                                       
                   move low-values to
                       instancedata(realindex:collectionstride)
                   invoke self "setempty" using i
               end-if
               divide i by asize giving temp remainder i
               add 1 to i
               invoke self "isEmptyat" using i returning bool
           end-perform
           invoke self "dealloc" using aptr
           exit method.
       end method "fixCollisionsFrom".

      *>----------------------------------------------------------------
      *> Return a new ValueSet which containing those elements which
      *> are in this ValueSet but not in aCollection.
      *>----------------------------------------------------------------
       method-id. "minus".
       local-storage section.
       01 amessageselector     pic x(80).
       01 amessage2            usage object reference.

       linkage section.
       01 anewcollection       usage object reference.
       01 acollection          usage object reference.

       procedure division using acollection
                           returning anewcollection.
           move "includes" to amessageselector
           invoke callback "new" using acollection amessageselector
                                     returning amessage2
           invoke self "reject" using amessage2
                                   returning anewcollection
           exit method.
       end method "minus".
      *>---------------------------------------------------------------
      *> PRIVATE. Mark the position anIndex as Occuppied
      *>---------------------------------------------------------------
       method-id. "setOccuppied".
       local-storage section.
       01 i                    pic s9(9) comp-5.
       01 abit             pic x comp-5.
       01 anoffset         pic s9(9) comp-5.
       01 amask            pic x comp-x.

       linkage section.
       01 anindex              pic s9(9) comp-5.
       01 instanceData         pic x.
       procedure division using anindex.
           divide anindex by 8 giving anoffset remainder abit
           add 1 to anoffset
           move 1 to amask
           perform abit times
               multiply 2 by amask
           end-perform
           move 1 to i
           set address of instanceData to collptr
           call "CBL_OR" using amask
                    instancedata(anoffset + storagerequirements:i)
                    by value 1
           exit method.
       end method "setOccuppied".

      *>---------------------------------------------------------------
      *> PRIVATE. Mark the position anIndex as empty
      *>---------------------------------------------------------------
       method-id. "setEmpty".
       local-storage section.
       01 i                pic s9(9) comp-5.
       01 abit             pic x comp-5.
       01 anoffset         pic s9(9) comp-5.
       01 amask            pic x comp-x.
       01 afullmask        pic x comp-x.

       linkage section.
       01 anindex          pic s9(9) comp-5.
       01 instanceData     pic x.

       procedure division using anindex.
           move h"FF" to afullmask
           divide anindex by 8 giving anoffset remainder abit
           add 1 to anoffset
           move 1 to amask
           perform abit times
               multiply 2 by amask
           end-perform
           call "CBL_XOR" using afullmask amask by value 1
           move 1 to i
           set address of instanceData to collptr
           call "CBL_AND" using amask
                    instancedata(anoffset + storagerequirements:i)
                             by value 1
           exit method.
       end method "setEmpty".
      *>---------------------------------------------------------------
      *> PRIVATE. If the location indicated by anIndex is empty then
      *> return true otherwise return false.
      *>---------------------------------------------------------------
       method-id. "isEmptyAt".
       local-storage section.
       01 anemptybyte      pic x comp-x.
       01 anebyte redefines anemptybyte pic x.
       01 i                pic s9(9) comp-5.
       01 amask            pic x comp-x.
       01 abit             pic x comp-5.
       01 anoffset         pic s9(9) comp-5.

       linkage section.
       01 anindex              pic s9(9) comp-5.
       01 lnkbool                 pic x comp-5.
           88 lnkistrue           value 1.
           88 lnkisfalse          value 0.
       01 instanceData         pic x.
       procedure division using anindex returning lnkbool.
           divide anindex by 8 giving anoffset remainder abit
           add 1 to anoffset
           move 1 to amask
           perform abit times
               multiply 2 by amask
           end-perform

           add storagerequirements to anOffset
           set address of instanceData to collptr
           move instancedata(anoffset:1) to anebyte

           call "CBL_AND" using amask anemptybyte by value 1
           if anemptybyte > 0
               set lnkisfalse to true
           else
               set lnkistrue to true
           end-if
           exit method.
       end method "isEmptyAt".

      *>---------------------------------------------------------------
      *> PRIVATE. If the location indicated by anIndex is occuppied then
      *> return true otherwise return false.
      *>---------------------------------------------------------------
       method-id. "isOccuppiedAt".
       local-storage section.
       01 anemptybyte      pic x comp-x.
       01 anebyte          redefines anemptybyte pic x.
       01 i                pic s9(9) comp-5.
       01 amask            pic x comp-x.
       01 abit             pic x comp-5.
       01 anoffset         pic s9(9) comp-5.

       linkage section.
       01 anindex           pic s9(9) comp-5.
       01 lnkbool           pic x comp-5.
           88 lnkistrue     value 1.
           88 lnkisfalse    value 0.
       01 instanceData      pic x.
       procedure division using anindex returning lnkbool.
           divide anindex by 8 giving anoffset remainder abit
           add 1 to anoffset
           move 1 to amask
           perform abit times
               multiply 2 by amask
           end-perform

           add storagerequirements to anOffset
           set address of instanceData to collptr
           move instancedata(anoffset:1) to anebyte
           call "CBL_AND" using amask anemptybyte by value 1
           if anemptybyte > 0
               set lnkistrue to true
           else
               set lnkisfalse to true
           end-if
           exit method.
       end method "isOccuppiedAt".



      *>----------------------------------------------------------------
      *> PRIVATE. Returns the storage requirements for this collection.
      *>----------------------------------------------------------------
       method-id. "getStorageRequirements".
       linkage section.
       01 lnkRequirements  pic x(4) comp-5.
       procedure division returning lnkRequirements.
           move storageRequirements to lnkRequirements
           add emptybits to lnkRequirements
           exit method.
       end method "getStorageRequirements".

      *>----------------------------------------------------------------
      *> Return a shallow copy of the receiver
      *>----------------------------------------------------------------
       method-id. "Copy".
       local-storage section.
       01 lsCopyPtr            pointer.
       01 lsCopySize           pic x(4) comp-5.
       linkage section.
       01 result               usage object reference.
       01 instanceData         pic x.
       01 lnkCopy              pic x.
       procedure division returning result.
           invoke super "basicCopy" returning result
           add emptyBits to storagerequirements giving lsCopySize
           invoke self "malloc" using lsCopySize returning lsCopyPtr
           set address of lnkCopy to lsCopyPtr
           set address of instanceData to collptr
           move instanceData(1:lsCopySize) to
                lnkCopy(1:lsCopySize)
      $if GC defined
           if collectiontemplate = null
                call "oopstableaddref" using by value numberElements
                                             by value collectionStride
                                             by value collPtr
           end-if
      $end
           invoke result "setCollPtr" using lsCopyPtr
           exit method.
       end method "Copy".

      $if gc defined
      *>----------------------------------------------------------------
      *> De-allocate memory for collection.
      *>----------------------------------------------------------------
       method-id. "decreaseReferences".
       local-storage section.
       01 lsBool                pic x comp-5.
        88 storingObjects          value 1.
        88 notstoringObjects       value 0.
       procedure division.
           if collectionTemplate = null
                call "oopstablerelease" using by value capacity
                                              by value collectionStride
                                              by value collptr                                              
                
           else
                invoke collectionTemplate "storingObjects"
                                returning lsBool
                if storingObjects
                     invoke self "decreaseStaticReferences"
                end-if
           end-if
           exit method.
       end method "decreaseReferences".

      *>----------------------------------------------------------------
      *> De-allocate memory for collection.
      *>----------------------------------------------------------------
       method-id. "decreaseStaticReferences".
       local-storage section.
       01 i             pic x(4) comp-5.
       01 lsPtr         pointer.

       linkage section.
       01 lnkElement    COLLECTABLE.
       procedure division.
           invoke self "allocateElement" returning lsPtr
           set address of lnkElement to lsPtr
           perform varying i from 1 by 1 until i > capacity
                invoke self "basicAtNoGC" using i
                                returning lnkElement
                invoke lnkElement as
                        collectionTemplate "decreaseReferences"
           end-perform
           invoke self "dealloc" using lsPtr
           exit method.
       end method "decreaseStaticReferences".

      $end

       end object.
       end class ValueSet.
