mirror of
https://github.com/c-cube/sidekick.git
synced 2025-12-06 11:15:43 -05:00
Fix for vector resizing in 'set'
This commit is contained in:
parent
c1af34823c
commit
e0ac6b31fd
2 changed files with 9 additions and 11 deletions
2
_tags
2
_tags
|
|
@ -11,5 +11,5 @@
|
||||||
|
|
||||||
# more warnings
|
# more warnings
|
||||||
<**/*.ml>: warn_K, warn_Y, warn_X
|
<**/*.ml>: warn_K, warn_Y, warn_X
|
||||||
|
|
||||||
<**/*.cm*>: debug
|
<**/*.cm*>: debug
|
||||||
|
|
||||||
|
|
|
||||||
18
util/vec.ml
18
util/vec.ml
|
|
@ -82,15 +82,14 @@ let last t =
|
||||||
|
|
||||||
let get t i =
|
let get t i =
|
||||||
if i < 0 || i >= t.sz then invalid_arg "vec.get";
|
if i < 0 || i >= t.sz then invalid_arg "vec.get";
|
||||||
Array.unsafe_get t.data i
|
Array.get t.data i
|
||||||
|
|
||||||
let set t i v =
|
let set t i v =
|
||||||
if i < 0 || i > t.sz then invalid_arg "vec.set";
|
if i < 0 || i > t.sz then invalid_arg "vec.set";
|
||||||
if i = t.sz then begin
|
if i = t.sz then
|
||||||
grow_to_double_size t;
|
push t v
|
||||||
t.sz <- i + 1
|
else
|
||||||
end;
|
Array.set t.data i v
|
||||||
Array.unsafe_set t.data i v
|
|
||||||
|
|
||||||
let copy t =
|
let copy t =
|
||||||
let data = Array.copy t.data in
|
let data = Array.copy t.data in
|
||||||
|
|
@ -100,7 +99,6 @@ let move_to t t' =
|
||||||
t'.data <- Array.copy t.data;
|
t'.data <- Array.copy t.data;
|
||||||
t'.sz <- t.sz
|
t'.sz <- t.sz
|
||||||
|
|
||||||
|
|
||||||
let remove t e =
|
let remove t e =
|
||||||
let j = ref 0 in
|
let j = ref 0 in
|
||||||
while (!j < t.sz && not (t.data.(!j) == e)) do incr j done;
|
while (!j < t.sz && not (t.data.(!j) == e)) do incr j done;
|
||||||
|
|
@ -132,7 +130,7 @@ let fold f acc t =
|
||||||
if i=t.sz
|
if i=t.sz
|
||||||
then acc
|
then acc
|
||||||
else
|
else
|
||||||
let acc' = f acc (Array.unsafe_get t.data i) in
|
let acc' = f acc (Array.get t.data i) in
|
||||||
_fold f acc' t (i+1)
|
_fold f acc' t (i+1)
|
||||||
in _fold f acc t 0
|
in _fold f acc t 0
|
||||||
|
|
||||||
|
|
@ -141,7 +139,7 @@ exception ExitVec
|
||||||
let exists p t =
|
let exists p t =
|
||||||
try
|
try
|
||||||
for i = 0 to t.sz - 1 do
|
for i = 0 to t.sz - 1 do
|
||||||
if p (Array.unsafe_get t.data i) then raise ExitVec
|
if p (Array.get t.data i) then raise ExitVec
|
||||||
done;
|
done;
|
||||||
false
|
false
|
||||||
with ExitVec -> true
|
with ExitVec -> true
|
||||||
|
|
@ -149,7 +147,7 @@ let exists p t =
|
||||||
let for_all p t =
|
let for_all p t =
|
||||||
try
|
try
|
||||||
for i = 0 to t.sz - 1 do
|
for i = 0 to t.sz - 1 do
|
||||||
if not (p (Array.unsafe_get t.data i)) then raise ExitVec
|
if not (p (Array.get t.data i)) then raise ExitVec
|
||||||
done;
|
done;
|
||||||
true
|
true
|
||||||
with ExitVec -> false
|
with ExitVec -> false
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue