Sparse and two-dimensional arrays

Two-dimensional arrays can store a lot of things, such as Go, Gobang, the whole board can be seen as a huge two-dimensional array, in which black and white chess can be represented by the number 1 or 2 in the array, blank space is generally represented by 0. But because the board is large, the corresponding two-dimensional array is also large, ...

Posted by RobM on Wed, 15 Sep 2021 13:21:12 -0700

java-fair lock-re-lockable-deadlock-interrupt (how to gracefully stop a thread)

1. Fair-Unfair 1.1 Ticket Selling Cases (Unfair) class Ticket { private int number = 50; private Lock lock = new ReentrantLock(); //The default is an unfair lock. If you want an average allocation, =--, to be fair, change the constructor parameter to true public void sale() { lock.lock(); try { ...

Posted by SuperCam on Mon, 13 Sep 2021 20:06:10 -0700

Rust: array, dynamic array, string -- thoroughly combing concepts and methods

Arrays and strings are essentially the same. They all correspond to a continuous piece of memory. In C language, a string is an unsigned char ending in a number zero   Array, that is, Rust's u8 array. C language array is a pointer. As for the size of the array, it is up to the programmer to manage it. The advantage of this is that the gra ...

Posted by storyteller on Thu, 09 Sep 2021 21:25:38 -0700