public void set(int key, int value) {
        if (map.containsKey(key)) {
            DLinkedListNode oldNode = map.get(key);
            oldNode.val = value;

            // 调整该节点到head
            removeNode(oldNode);
            setHead(oldNode);

        } else {
            DLinkedListNode newNode = new DLinkedListNode(key, value);
            if (len < capacity) {
                setHead(newNode);
                map.put(key, newNode);
                len++;
            } else {
                // 将末尾元素从map中删除
                map.remove(end.key);

                // 将末尾元素从dlink中移除
                end = end.pre;
                if (end != null) {
                    end.next = null;
                }

                setHead(newNode);
                map.put(key, newNode);
            }
        }
    }