@@ -19,20 +19,35 @@ Base.convert(::Type{Factorization}, d::AbstractDict) = Factorization(d)
19
19
Base. iterate (f:: Factorization , state... ) = iterate (f. pe, state... )
20
20
21
21
function Base. get (f:: Factorization , p, default)
22
- found = searchsorted (f. pe, p, by= first)
23
- isempty (found) ?
24
- default :
25
- last (f. pe[first (found)])
22
+ found = searchsortedfirst (f. pe, p, by= first)
23
+ (found > length (f. pe) || first (f. pe[found])) != p ? default : last (f. pe[found])
26
24
end
27
25
28
26
Base. getindex (f:: Factorization , p:: Integer ) = get (f, p, 0 )
29
27
30
28
function Base. setindex! (f:: Factorization{T} , e:: Int , p:: Integer ) where T
31
- found = searchsorted (f. pe, p, by= first)
32
- if isempty (found)
33
- insert! (f. pe, first (found), T (p)=> e)
29
+ found = searchsortedfirst (f. pe, p, by= first)
30
+ if found > length (f. pe)
31
+ push! (f. pe, T (p)=> e)
32
+ elseif first (f. pe[found]) != p
33
+ insert! (f. pe, found, T (p)=> e)
34
34
else
35
- f. pe[first (found)] = T (p)=> e
35
+ f. pe[found] = T (p)=> e
36
+ end
37
+ f
38
+ end
39
+
40
+ """
41
+ impliments f[p] += e faster
42
+ """
43
+ function increment! (f:: Factorization{T} , e:: Int , p:: Integer ) where T
44
+ found = searchsortedfirst (f. pe, p, by= first)
45
+ if found > length (f. pe)
46
+ push! (f. pe, T (p)=> e)
47
+ elseif first (f. pe[found]) != p
48
+ insert! (f. pe, found, T (p)=> e)
49
+ else
50
+ f. pe[found] = T (p)=> (last (f. pe[found])+ e)
36
51
end
37
52
f
38
53
end
0 commit comments