Skip to content

Instantly share code, notes, and snippets.

View lichenbo's full-sized avatar
🏠
Working from home

Chenbo Li lichenbo

🏠
Working from home
View GitHub Profile
public ArrayList(int initialCapacity) {
super();
if (initialCapacity < 0)
throw new IllegalArgumentException("Illegal Capacity: "+
initialCapacity);
this.elementData = new Object[initialCapacity];
}
public ArrayList() {
this(10);
public class ArrayList<E> extends AbstractList<E>
implements List<E>, RandomAccess, Cloneable, java.io.Serializable
{
private static final long serialVersionUID = 8683452581122892189L;
private transient Object[] elementData;
private int size;
...
list_t * map (void * (*f)(void*, void*), void* env, list_t* xs) {
if (xs == NULL)
return NULL;
return makelist(f(env, xs->head), map(f, env, xs->tail));
}
interface Func<B,A> {
B m(A x);
}
static <A,B> List<B> map(Func<B,A> f, List<A> xs) {
if (xs == null) return null;
return new List<B>(f.m(xs.head),map(f,xs.tail));
}
static List<Integer> doubleAll (List<Integer> xs) {
00401488 mov -0x4(%ebp),%eax ;i赋给$eax(i已被初始化为0)
0040148B shl $0x2,%eax ;$eax向左移2位(即乘4来计算偏移量)
0040148E add -0x10(%ebp),%eax ;$eax加上基址,计算出data[i]的地址,赋给$eax
00401491 mov (%eax),%eax ;取出data[i]的数据,并且赋给$eax
00401493 mov -0x8(%ebp),%edx ;取出x,赋给%edx
00401496 imul %edx,%eax ;$eax = $edx * $eax
00401499 mov %eax,-0x8(%ebp) ;x = $eax
0040149C incl -0x4(%ebp) ;i++
0040149F mov -0x4(%ebp),%eax ;i赋给eax
004014A2 cmp -0xc(%ebp),%eax ;比较length和i
| |高地址
| | <- 28fefb - 28fef8($ebp)
| i | <- 28fef7 - 28fef4
| x | <- 28fef3 - 28fef0
| length | <- 28feef - 28feec
| base | <- 28feeb - 28fee7
----------- 低地址
00401488 mov -0x4(%ebp),%eax
0040148B shl $0x2,%eax
0040148E add -0x10(%ebp),%eax
00401491 mov (%eax),%eax
00401493 mov -0x8(%ebp),%edx
00401496 imul %edx,%eax
00401499 mov %eax,-0x8(%ebp)
0040149C incl -0x4(%ebp)
0040149F mov -0x4(%ebp),%eax
004014A2 cmp -0xc(%ebp),%eax
for( i = 0; i < length; i++)
x = x OPER data[i];
*dest = x;
#include <stdio.h>
#include <stdlib.h>
#define IDENT 1
#define OPER *
typedef int data_t;
typedef struct {
int len;
data_t *data;
import java.util.Arrays;
import java.util.Random;
public class Main
{
public static void main(String[] args)
{
// Generate data
int arraySize = 32768;
int data[] = new int[arraySize];