-
Notifications
You must be signed in to change notification settings - Fork 641
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #65 from Viscaria233/master
代码完成
- Loading branch information
Showing
59 changed files
with
956 additions
and
262 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>coderising</groupId> | ||
<artifactId>coding2017</artifactId> | ||
<version>1.0-SNAPSHOT</version> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<configuration> | ||
<source>1.8</source> | ||
<target>1.8</target> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
<dependencies> | ||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<version>4.12</version> | ||
</dependency> | ||
</dependencies> | ||
|
||
|
||
</project> |
68 changes: 0 additions & 68 deletions
68
group01/895457260/code/src/download/FileDownloaderTest.java
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
10 changes: 0 additions & 10 deletions
10
group01/895457260/code/src/download/api/ConnectionManager.java
This file was deleted.
Oops, something went wrong.
8 changes: 0 additions & 8 deletions
8
group01/895457260/code/src/download/api/DownloadListener.java
This file was deleted.
Oops, something went wrong.
59 changes: 0 additions & 59 deletions
59
group01/895457260/code/src/download/impl/ConnectionImpl.java
This file was deleted.
Oops, something went wrong.
12 changes: 0 additions & 12 deletions
12
group01/895457260/code/src/download/impl/ConnectionManagerImpl.java
This file was deleted.
Oops, something went wrong.
File renamed without changes.
112 changes: 112 additions & 0 deletions
112
group01/895457260/code/src/main/java/algorithm/lru/LRUPageFrame.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
package algorithm.lru; | ||
|
||
/** | ||
* 用双向链表实现LRU算法 | ||
* @author liuxin | ||
* | ||
*/ | ||
public class LRUPageFrame { | ||
private static class List { | ||
int capacity; | ||
int size; | ||
Node head;// 链表头 | ||
Node rear;// 链表尾 | ||
static class Node { | ||
Node pre; | ||
Node next; | ||
int pageNum; | ||
Node() {} | ||
void clear() { | ||
pre = null; | ||
next = null; | ||
} | ||
} | ||
List(int capacity) { | ||
this.capacity = capacity; | ||
head = new Node(); | ||
rear = new Node(); | ||
head.next = rear; | ||
rear.pre = head; | ||
} | ||
void put(int pageNum) { | ||
Node node = findNode(pageNum); | ||
if (node == null) { | ||
if (size >= capacity) { | ||
remove(); | ||
} | ||
Node n = new Node(); | ||
n.pageNum = pageNum; | ||
n.next = rear; | ||
n.pre = rear.pre; | ||
n.pre.next = n; | ||
rear.pre = n; | ||
size++; | ||
} else { | ||
pullUp(node); | ||
} | ||
} | ||
Node findNode(int pageNum) { | ||
for (Node n = head.next; n != null && n != rear; n = n.next) { | ||
if (n.pageNum == pageNum) { | ||
return n; | ||
} | ||
} | ||
return null; | ||
} | ||
void remove() { | ||
if (size == 0) { | ||
return; | ||
} | ||
List.Node node = head.next; | ||
node.next.pre = head; | ||
head.next = node.next; | ||
node.clear(); | ||
size--; | ||
} | ||
void pullUp(Node node) { | ||
node.next.pre = node.pre; | ||
node.pre.next = node.next; | ||
node.next = rear; | ||
node.pre = rear.pre; | ||
rear.pre.next = node; | ||
rear.pre = node; | ||
} | ||
@Override | ||
public String toString() { | ||
StringBuilder buffer = new StringBuilder(); | ||
Node node = rear.pre; | ||
while(node != null && node != head){ | ||
buffer.append(node.pageNum); | ||
|
||
node = node.pre; | ||
if(node != null){ | ||
buffer.append(","); | ||
} | ||
} | ||
return buffer.length() == 0 ? "" : buffer.substring(0, buffer.length() - 1); | ||
} | ||
} | ||
|
||
private List buf; | ||
private int capacity; | ||
|
||
public LRUPageFrame(int capacity) { | ||
this.capacity = capacity; | ||
buf = new List(capacity); | ||
} | ||
|
||
/** | ||
* 获取缓存中对象 | ||
* | ||
* @param pageNum | ||
* @return | ||
*/ | ||
public void access(int pageNum) { | ||
buf.put(pageNum); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return buf.toString(); | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.