Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
SDA
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Julien David
SDA
Commits
e5158535
Commit
e5158535
authored
5 years ago
by
david
Browse files
Options
Downloads
Patches
Plain Diff
Ajout des fonctions augmentations et reudction capacité java
parent
3f2725fd
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
TP1/Java/ArrayListProxy.java
+23
-9
23 additions, 9 deletions
TP1/Java/ArrayListProxy.java
with
23 additions
and
9 deletions
TP1/Java/ArrayListProxy.java
+
23
−
9
View file @
e5158535
...
@@ -25,10 +25,9 @@ public class ArrayListProxy<T> {
...
@@ -25,10 +25,9 @@ public class ArrayListProxy<T> {
*/
*/
boolean
append
(
T
x
){
boolean
append
(
T
x
){
boolean
memory_allocation
=
false
;
boolean
memory_allocation
=
false
;
if
(
enlarg
ing
_capacity
()
){
if
(
do_we_need_to_
enlarg
e
_capacity
()
){
memory_allocation
=
true
;
memory_allocation
=
true
;
capacity
*=
2
;
enlarge_capacity
();
data
.
ensureCapacity
(
capacity
);
}
}
data
.
add
(
x
);
data
.
add
(
x
);
return
memory_allocation
;
return
memory_allocation
;
...
@@ -44,10 +43,9 @@ public class ArrayListProxy<T> {
...
@@ -44,10 +43,9 @@ public class ArrayListProxy<T> {
boolean
pop_back
(){
boolean
pop_back
(){
boolean
memory_reduction
=
false
;
boolean
memory_reduction
=
false
;
if
(!
data
.
isEmpty
()){
if
(!
data
.
isEmpty
()){
if
(
reduc
ing
_capacity
()
){
if
(
do_we_need_to_
reduc
e
_capacity
()
){
memory_reduction
=
true
;
memory_reduction
=
true
;
capacity
/=
2
;
reduce_capacity
();
data
.
ensureCapacity
(
capacity
);
}
}
data
.
remove
(
data
.
size
()-
1
);
data
.
remove
(
data
.
size
()-
1
);
}
}
...
@@ -77,20 +75,36 @@ public class ArrayListProxy<T> {
...
@@ -77,20 +75,36 @@ public class ArrayListProxy<T> {
Cette fonction détermine la règle selon laquelle un espace mémoire plus grand sera alloué ou non.
Cette fonction détermine la règle selon laquelle un espace mémoire plus grand sera alloué ou non.
@returns true si le tableau doit être agrandi, false sinon.
@returns true si le tableau doit être agrandi, false sinon.
*/
*/
private
boolean
enlarg
ing
_capacity
()
{
private
boolean
do_we_need_to_
enlarg
e
_capacity
()
{
return
data
.
size
()
>=
(
capacity
*
3
)/
4
;
return
data
.
size
()
>=
(
capacity
*
3
)/
4
;
}
}
/**
Cette fonction augmente la capacité du tableau.
*/
private
void
enlarge_capacity
(){
capacity
*=
2
;
data
.
ensureCapacity
(
capacity
);
}
/**
/**
Cette fonction détermine la règle selon laquelle un espace mémoire plus petit sera alloué ou non.
Cette fonction détermine la règle selon laquelle un espace mémoire plus petit sera alloué ou non.
@returns true si le tableau doit être réduit, false sinon.
@returns true si le tableau doit être réduit, false sinon.
*/
*/
private
boolean
reduc
ing
_capacity
(){
private
boolean
do_we_need_to_
reduc
e
_capacity
(){
return
data
.
size
()
<=
capacity
/
4
&&
data
.
size
()
>
4
;
return
data
.
size
()
<=
capacity
/
4
&&
data
.
size
()
>
4
;
}
}
/**
Cette fonction reduit la capacité du tableau.
*/
void
reduce_capacity
(){
capacity
/=
2
;
data
.
ensureCapacity
(
capacity
);
}
// Tableau dynamique en Java. Sa capacité réelle est masquée, mais on peut avoir un contrôle dessus.
// Tableau dynamique en Java. Sa capacité réelle est masquée, mais on peut avoir un contrôle dessus.
private
ArrayList
<
T
>
data
;
private
ArrayList
<
T
>
data
;
// Capacité réelle du tableau data.
// Capacité réelle du tableau data.
private
int
capacity
;
private
int
capacity
;
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment