ARTS第十三周打卡

1.Algorithm

https://leetcode-cn.com/problems/implement-strstr/

public class Demo {

    public static void main(String[] args) {
        int i = strStr("helloeeeee", "lloeee");
        System.out.println(i);

    }


    public static int strStr(String haystack, String needle) {
        //如果needle为空,则返回0
        if(needle.length()<1){
            return 0;
        }
        if(haystack == null || needle == null || haystack.length() < 1 || needle.length() < 1){
            return -1;
        }

        //主字符串haystack的下标
        int index1 = 0;
        //模式串needle的下标
        int index2 = 0;
        char[] char1 = haystack.toCharArray();
        char[] char2 = needle.toCharArray();
        //获得nexts数组
        int[] nexts = getNexts(char2);
        while(index1 < char1.length && index2 < char2.length){
            if(char1[index1] == char2[index2]){
                index1++;
                index2++;
            }else if(nexts[index2] == -1){//如果为第一位都不匹配则直接下一个字符
                index1++;
            }else{
                index2 = nexts[index2];
            }
        }
        return index2 == char2.length ? index1 - index2 : -1;
    }
    //获得next数组
    public static int[] getNexts(char[] str2){
        if(str2.length == 1){
            return new int[]{-1};
        }
        int[] nexts = new int[str2.length];
        nexts[0] = -1;
        nexts[1] = 0;
        //指向当前元素最长前缀的指
        int cn = 0;
        //遍历字符串时的下标
        int index = 2;
        while(index < str2.length){
            if(str2[index - 1] == str2[cn]){
                nexts[index++] = ++cn;
            }else if(cn > 0){
                cn = nexts[cn];
            }else{
                nexts[index++] = 0;
            }
        }
        return nexts;
    }

}

  

2.Review

 https://redis.io/topics/memory-optimization

  1.聚合类型的特殊转码

    使用 redis.conf 来调整特殊编码类型的最大元素数和最大元素的最大值,如果特殊编码的值超过设置最大值的大小,redis将自动转为正常编码

hash-max-zipmap-entries 512 (hash-max-ziplist-entries for Redis >= 2.6)
hash-max-zipmap-value 64  (hash-max-ziplist-value for Redis >= 2.6)
list-max-ziplist-entries 512
list-max-ziplist-value 64
zset-max-ziplist-entries 128
zset-max-ziplist-value 64
set-max-intset-entries 512

  2.Using 32 bit instances(使用32位实例)

    使用32位目标编译的redis的key 都要小的很多,因为他的指针小,RDB和AOF文件在32位和64位之间兼容,所以32位和64位之间可以随便切换

  3.bit and byte level operations(位和字节级操作)

    

  4.Use hashes when possible(尽可能使用hash)

3.Tip

insert into () values()
on DUPLICATE KEY UPDATE ()

  mybaits  DUPLICATE 关键字 在主键冲突时候 insert 语句将变为 update 语句

4.Share

  https://www.cnblogs.com/panda777/p/11179057.html

  jvm面试题分享

原文地址:https://www.cnblogs.com/panda777/p/11185844.html