Skip to content

Commit

Permalink
Merge pull request #65 from Viscaria233/master
Browse files Browse the repository at this point in the history
代码完成
  • Loading branch information
zavier authored Mar 31, 2017
2 parents b7c5768 + 833b507 commit 3a8f57b
Show file tree
Hide file tree
Showing 59 changed files with 956 additions and 262 deletions.
31 changes: 31 additions & 0 deletions group01/895457260/code/pom.xml
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 group01/895457260/code/src/download/FileDownloaderTest.java

This file was deleted.

23 changes: 0 additions & 23 deletions group01/895457260/code/src/download/api/Connection.java

This file was deleted.

10 changes: 0 additions & 10 deletions group01/895457260/code/src/download/api/ConnectionManager.java

This file was deleted.

8 changes: 0 additions & 8 deletions group01/895457260/code/src/download/api/DownloadListener.java

This file was deleted.

59 changes: 0 additions & 59 deletions group01/895457260/code/src/download/impl/ConnectionImpl.java

This file was deleted.

This file was deleted.

112 changes: 112 additions & 0 deletions group01/895457260/code/src/main/java/algorithm/lru/LRUPageFrame.java
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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,15 @@
*
*/
public class Config {
public static final String packageName = "download";

/**
* 保存下载文件的目录
*/
public static File targetDirectory = new File("download/");
public static File tempDirectory = new File(targetDirectory, "temp/");

public static int maxLengthPerThread = 10 * 1024 * 1024;
public static int minThreadCount = 3;
public static int maxThreadCount = 8;
}
Loading

0 comments on commit 3a8f57b

Please sign in to comment.