This file is indexed.

/usr/share/axiom-20170501/src/algebra/HEAP.spad is in axiom-source 20170501-3.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
)abbrev domain HEAP Heap
++ Author: Michael Monagan and Stephen Watt
++ Date Created:June 86 and July 87
++ Date Last Updated:Feb 92
++ Description:
++ Heap implemented in a flexible array to allow for insertions
++ Complexity: O(log n) insertion, extraction and O(n) construction
--% Dequeue and Heap data types
 
Heap(S) : SIG == CODE where
  S : OrderedSet

  SIG ==> PriorityQueueAggregate S with

    heap : List S -> %
      ++ heap(ls) creates a heap of elements consisting of the 
      ++ elements of ls.
      ++
      ++X i:Heap INT := heap [1,6,3,7,5,2,4]

    -- Inherited Signatures repeated for examples documentation

    bag : List S -> %
      ++
      ++X bag([1,2,3,4,5])$Heap(INT)

    copy : % -> %
      ++
      ++X a:Heap INT:= heap [1,2,3,4,5]
      ++X copy a

    empty? : % -> Boolean
      ++
      ++X a:Heap INT:= heap [1,2,3,4,5]
      ++X empty? a

    empty : () -> %
      ++
      ++X b:=empty()$(Heap INT)

    eq? : (%,%) -> Boolean
      ++
      ++X a:Heap INT:= heap [1,2,3,4,5]
      ++X b:=copy a
      ++X eq?(a,b)

    extract_! : % -> S
      ++
      ++X a:Heap INT:= heap [1,2,3,4,5]
      ++X extract! a
      ++X a

    insert_! : (S,%) -> %
      ++
      ++X a:Heap INT:= heap [1,2,3,4,5]
      ++X insert!(8,a)
      ++X a

    inspect : % -> S
      ++
      ++X a:Heap INT:= heap [1,2,3,4,5]
      ++X inspect a

    map : ((S -> S),%) -> %
      ++
      ++X a:Heap INT:= heap [1,2,3,4,5]
      ++X map(x+->x+10,a)
      ++X a

    max : % -> S
      ++
      ++X a:Heap INT:= heap [1,2,3,4,5]
      ++X max a

    merge : (%,%) -> %
      ++
      ++X a:Heap INT:= heap [1,2,3,4,5]
      ++X b:Heap INT:= heap [6,7,8,9,10]
      ++X merge(a,b)

    merge! : (%,%) -> %
      ++
      ++X a:Heap INT:= heap [1,2,3,4,5]
      ++X b:Heap INT:= heap [6,7,8,9,10]
      ++X merge!(a,b)
      ++X a
      ++X b

    sample : () -> %
      ++
      ++X sample()$Heap(INT)

    less? : (%,NonNegativeInteger) -> Boolean
      ++
      ++X a:Heap INT:= heap [1,2,3,4,5]
      ++X less?(a,9)

    more? : (%,NonNegativeInteger) -> Boolean
      ++
      ++X a:Heap INT:= heap [1,2,3,4,5]
      ++X more?(a,9)

    size? : (%,NonNegativeInteger) -> Boolean
      ++
      ++X a:Heap INT:= heap [1,2,3,4,5]
      ++X size?(a,5)

    if $ has shallowlyMutable then

      map! :  ((S -> S),%) -> %
        ++
        ++X a:Heap INT:= heap [1,2,3,4,5]
        ++X map!(x+->x+10,a)
        ++X a

    if S has SetCategory then

      latex : % -> String
        ++
        ++X a:Heap INT:= heap [1,2,3,4,5]
        ++X latex a

      hash : % -> SingleInteger
        ++
        ++X a:Heap INT:= heap [1,2,3,4,5]
        ++X hash a

      coerce : % -> OutputForm
        ++
        ++X a:Heap INT:= heap [1,2,3,4,5]
        ++X coerce a

      "=": (%,%) -> Boolean
        ++
        ++X a:Heap INT:= heap [1,2,3,4,5]
        ++X b:Heap INT:= heap [1,2,3,4,5]
        ++X (a=b)@Boolean

      "~=" : (%,%) -> Boolean
        ++
        ++X a:Heap INT:= heap [1,2,3,4,5]
        ++X b:=copy a
        ++X (a~=b)

    if % has finiteAggregate then

      every? : ((S -> Boolean),%) -> Boolean
        ++
        ++X a:Heap INT:= heap [1,2,3,4,5]
        ++X every?(x+->(x=4),a)

      any? : ((S -> Boolean),%) -> Boolean
        ++
        ++X a:Heap INT:= heap [1,2,3,4,5]
        ++X any?(x+->(x=4),a)

      count :  ((S -> Boolean),%) -> NonNegativeInteger
        ++
        ++X a:Heap INT:= heap [1,2,3,4,5]
        ++X count(x+->(x>2),a)

      _# : % -> NonNegativeInteger
        ++
        ++X a:Heap INT:= heap [1,2,3,4,5]
        ++X #a

      parts : % -> List S
        ++
        ++X a:Heap INT:= heap [1,2,3,4,5]
        ++X parts a

      members : % -> List S
        ++
        ++X a:Heap INT:= heap [1,2,3,4,5]
        ++X members a

    if % has finiteAggregate and S has SetCategory then

      member? : (S,%) -> Boolean
        ++
        ++X a:Heap INT:= heap [1,2,3,4,5]
        ++X member?(3,a)

      count : (S,%) -> NonNegativeInteger
        ++
        ++X a:Heap INT:= heap [1,2,3,4,5]
        ++X count(4,a)

  CODE ==> IndexedFlexibleArray(S,0) add

    Rep := IndexedFlexibleArray( S,0)

    empty() == empty()$Rep

    heap l == 
      n := #l
      h := empty()
      n = 0 => h
      for x in l repeat insert_!(x,h)
      h

    siftUp: (%,Integer,Integer) -> Void
    siftUp(r,i,n) ==
       -- assertion 0 <= i < n
       t := r.i
       while (j := 2*i+1) < n repeat
          if (k := j+1) < n and r.j < r.k then j := k
          if t < r.j then (r.i := r.j; r.j := t; i := j) else leave
 
    extract_! r ==
       -- extract the maximum from the heap O(log n)
       n := #r :: Integer
       n = 0 => error "empty heap"
       t := r(0)
       r(0) := r(n-1)
       delete_!(r,n-1)
       n = 1 => t
       siftUp(r,0,n-1)
       t
 
    insert_!(x,r) ==
       -- Williams' insertion algorithm O(log n)
       j := (#r) :: Integer
       r:=concat_!(r,concat(x,empty()$Rep))
       while j > 0 repeat
          i := (j-1) quo 2
          if r(i) >= x then leave
          r(j) := r(i)
          j := i
       r(j):=x
       r
 
    max r == if #r = 0 then error "empty heap" else r.0

    inspect r == max r
 
    makeHeap(r:%):% ==
       -- Floyd's heap construction algorithm O(n)
       n := #r
       for k in n quo 2 -1 .. 0 by -1 repeat siftUp(r,k,n)
       r

    bag l == makeHeap construct(l)$Rep

    merge(a,b) == makeHeap concat(a,b)

    merge_!(a,b) == makeHeap concat_!(a,b)