MCPcopy Create free account
hub / github.com/EdwardRaff/JSAT / add

Method add

JSAT/src/jsat/utils/BoundedSortedList.java:33–76  ·  view source on GitHub ↗
(E e)

Source from the content-addressed store, hash-verified

31
32
33 @Override
34 public boolean add(E e)
35 {
36 if(isEmpty())
37 {
38 super.add(e);
39 return true;
40 }
41 else
42 {
43 int ind = Collections.binarySearch(this, e);
44 if (ind >= 0)//it is already in the list,
45 {
46 if (size() == maxSize)//pop the last, put this
47 {
48 this.remove(maxSize - 1);
49 super.add(ind, e);
50 }
51 else//not full yet, can jsut add
52 {
53 if(ind > size())
54 super.add(e);
55 else
56 super.add(ind, e);
57 }
58 return true;
59 }
60 else
61 {
62 ind = -(ind + 1);//Now it is the point where it should be inserted
63 if (size() < maxSize)
64 super.add(ind, e);
65 else if (ind < maxSize)
66 {
67 this.remove(maxSize - 1);
68 super.add(ind, e);
69 }
70 else
71 return false;
72
73 return true;
74 }
75 }
76 }
77
78
79 public E first()

Callers 9

searchMethod · 0.95
searchMethod · 0.95
searchMethod · 0.95
searchMethod · 0.95
runMethod · 0.95
searchMethod · 0.95
searchMethod · 0.95
bruteMethod · 0.95
runMethod · 0.95

Calls 2

sizeMethod · 0.65
removeMethod · 0.45

Tested by

no test coverage detected