From d018a3fa632949bfe2d60038e7a1d0c6488fc0ff Mon Sep 17 00:00:00 2001 From: orajavac Date: Tue, 28 Mar 2017 17:04:46 +0800 Subject: [PATCH] =?UTF-8?q?20170328=5F1702=203.26=E4=BD=9C=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../basic/linklist/LRUPageFrame.java | 133 ++++++++ .../basic/linklist/LRUPageFrameTest.java | 29 ++ .../coding2017/basic/linklist/LinkedList.java | 290 ++++++++++++++++++ .../jvm/loader/ClassFileLoader.java | 51 +++ .../jvm/test/ClassFileloaderTest.java | 85 +++++ .../coding2017/jvm/test/EmployeeV1.java | 26 ++ 6 files changed, 614 insertions(+) create mode 100644 group02/562768642/src/com/github/orajavac/coding2017/basic/linklist/LRUPageFrame.java create mode 100644 group02/562768642/src/com/github/orajavac/coding2017/basic/linklist/LRUPageFrameTest.java create mode 100644 group02/562768642/src/com/github/orajavac/coding2017/basic/linklist/LinkedList.java create mode 100644 group02/562768642/src/com/github/orajavac/coding2017/jvm/loader/ClassFileLoader.java create mode 100644 group02/562768642/src/com/github/orajavac/coding2017/jvm/test/ClassFileloaderTest.java create mode 100644 group02/562768642/src/com/github/orajavac/coding2017/jvm/test/EmployeeV1.java diff --git a/group02/562768642/src/com/github/orajavac/coding2017/basic/linklist/LRUPageFrame.java b/group02/562768642/src/com/github/orajavac/coding2017/basic/linklist/LRUPageFrame.java new file mode 100644 index 0000000000..3240f2558c --- /dev/null +++ b/group02/562768642/src/com/github/orajavac/coding2017/basic/linklist/LRUPageFrame.java @@ -0,0 +1,133 @@ +package com.github.orajavac.coding2017.basic.linklist; + +public class LRUPageFrame { +private static class Node { + + Node prev; + Node next; + int pageNum=10000; + String flag; + + Node() { + } + } + + private int capacity; + private int length; + + + private Node first;// 链表头 + private Node last;// 链表尾 + + + public LRUPageFrame(int capacity) { + + this.capacity = capacity; + + first = new Node(); + last = new Node(); + last.flag = "last"; //用来标识最后一个节点是链表尾,在这里链表尾并不算做内存页 + first.flag = "first"; //用来标识链表头,在这里链表头并不算做内存页 + first.next = last; + last.prev=first; + } + + /** + * 获取缓存中对象 + * + * @param key + * @return + */ + public void access(int pageNum) { + if(lookup(pageNum)){ + ; + }else{ + if (lengthlen||index<=0){ + throw new RuntimeException("下标不存在"+index); + } + Node e = head; + int i=0; + while (e.next != null){ + i++; + if (i == index){ + return e.next.data; + } + e=e.next; + } + return null; + } + + public Object remove(int index){ + int len=Integer.parseInt(head.data.toString()); + if (index>len||index<=0){ + throw new RuntimeException("下标不存在"+index); + } + Node e = head; + Object data = null; + int i=0; + while (e.next != null){ + i++; + if (i == index){ + len--; + head.data = len; + data = e.next.data; + e.next = e.next.next; + return data; + } + e=e.next; + } + return null; + } + + public Object removeFirst(){ + return remove(1); + } + + public Object removeLast(){ + return remove(Integer.parseInt(head.data.toString())); + } + + public void addFirst(Object o){ + Node e = head.next; + Node n = new Node(); + n.data=o; + n.next=e; + size++; + head.next=n; + head.data=size; + } + + public void addLast(Object o){ + add(o); + } + + public int size(){ + return Integer.parseInt(head.data.toString()); + } + + public void listNode(){ + Node n = head; + StringBuffer buffer = new StringBuffer(); + while (n.next!=null){ + buffer.append(n.next.data + " -> "); + n=n.next; + } + if(buffer.length()>0){ + System.out.print(buffer.substring(0,buffer.length()-3)); + System.out.println(); + } + } + + /** + * 把该链表逆置 + * 例如链表为 3->7->10 , 逆置后变为 10->7->3 + */ + public void reverse(){ + + } + + /** + * 从第i个元素开始, 删除length 个元素 , 注意i从0开始 + * @param i + * @param length + */ + public void remove(int i, int length){ + if (i <= 0 || length<=0){ + throw new RuntimeException("起始值、结束值都不能小于0等于"); + } + int len = length + i; + if (len > size){ + throw new RuntimeException("删除索引长度超过了链表长度"); + } + Node e = head; + int y = 0; + while (e.next != null){ + y++; + if (y == i){ + Node n = e.next; + while (n!=null){ + n = n.next; + if (y == length){ + break; + } + y++; + n=n.next; + } + } + e=e.next; + } + } + + /** + * 假定当前链表和list均包含已升序排列的整数 + * 从当前链表中取出那些list所指定的元素 + * 例如当前链表 = 11->101->201->301->401->501->601->701 + * listB = 1->3->4->6 + * 返回的结果应该是[101,301,401,601] + * @param list + */ + public int[] getElements(LinkedList list){ + if (list==null||list.head==null){ + throw new RuntimeException("集合没有初始化"); + } + int[] elements = new int[Integer.parseInt(list.head.data.toString())]; + Node l = list.head; + Node n = head; + int len = 0; + int i = 0; + while (l.next!=null){ + len = 0; + n=head; + while(n.next!=null){ + len++; + if(len==Integer.parseInt(l.next.data.toString())){ + elements[i]=Integer.parseInt(n.next.data.toString()); + i++; + break; + } + n=n.next; + } + l = l.next; + } + return elements; + } + + /** + * 删除一个单链表的前半部分 + * 例如:list = 2->5->7->8 , 删除以后的值为 7->8 + * 如果list = 2->5->7->8->10 ,删除以后的值为7,8,10 + + */ + public void removeFirstHalf(){ + + } + + /** + * 已知链表中的元素以值递增有序排列,并以单链表作存储结构。 + * 从当前链表中中删除在list中出现的元素 + + * @param list + */ + + public void subtract(LinkedList list){ + if (list==null||list.head==null){ + throw new RuntimeException("集合没有初始化"); + } + Node l = list.head; + Node n = head; + int i = 0; + while (l.next!=null){ + n=head; + i=0; + while(n.next!=null){ + i++; + if(n.next.data.equals(l.next.data)){ + remove(i); + break; + } + n=n.next; + } + l = l.next; + } + } + + /** + * 已知当前链表中的元素以值递增有序排列,并以单链表作存储结构。 + * 删除表中所有值相同的多余元素(使得操作后的线性表中所有元素的值均不相同) + */ + public void removeDuplicateValues(){ + + } + + /** + * 已知链表中的元素以值递增有序排列,并以单链表作存储结构。 + * 试写一高效的算法,删除表中所有值大于min且小于max的元素(若表中存在这样的元素) + * 11->101->201->301->401->501->601->701 + * @param min + * @param max + */ + public void removeRange(int min, int max){ + if (min<=0||max<=0||min>max){ + throw new RuntimeException("录入不正确:"+min+","+max+" 应该大于min且小于max的元素"); + } + Node n = head; + int data = 0; + Node p = null; + while(n.next != null){ + data=Integer.parseInt(n.next.data.toString()); //11 + if(data>min&&data clzPaths = new ArrayList(); + + public byte[] readBinaryCode(String className) { + byte[] b = null; + try{ + File clfile = new File(packageToPath(className)); + @SuppressWarnings("resource") + BufferedInputStream in = new BufferedInputStream(new FileInputStream(clfile)); + ByteArrayOutputStream out = new ByteArrayOutputStream(1024); + byte[] buffer = new byte[1024]; + int size = 0; + while ((size = in.read(buffer)) != -1) { + out.write(buffer, 0, size); + } + b = out.toByteArray(); + }catch(Exception e){ + e.printStackTrace(); + } + return b; + } + + + public void addClassPath(String path) { + clzPaths.add(path); + } + + + + public String getClassPath(){ + StringBuffer buffer = new StringBuffer(); + for (int i=0;i