Saturday, February 8, 2020

Retrieve data from a Map reverse-ordered by value and then ordered by key


Problem

Given a Map of strings to their frequencies. Find top N-most frequent strings. If there is a tie get lexicographically smallest names first.

Solution

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
List<String> findTopNNames(Map<String, Integer> data, int n) {
    Comparator<Map.Entry<String, Integer>> cmpByValueDesc =
        Map.Entry.comparingByValue(Comparator.reverseOrder());

    Comparator<Map.Entry<String, Integer>> cmpByKey =
        Map.Entry.comparingByKey();

    Comparator<Map.Entry<String, Integer>> cmp =
        cmpByValueDesc.thenComparing(cmpByKey);

    return data.entrySet().stream()
        .sorted(cmp)
        .map(Map.Entry::getKey)
        .limit(n)
        .collect(Collectors.toList());
}

Tuesday, February 4, 2020

[WORKAROUND] Could not load GLX/OpenGL functions /usr/lib64/VirtualGL/libvglfaker.so: undefined symbol: glXGetProcAddressARB

I've encountered the following problem while starting IntelliJ IDEA via optirun:

$ optirun -c yuv ./idea-IC-193.5662.53/bin/idea.sh
...
[VGL] ERROR: Could not load GLX/OpenGL functions
[VGL] /usr/lib64/VirtualGL/libvglfaker.so: undefined symbol: glXGetProcAddressARB

Quick search gave me this link - https://github.com/VirtualGL/virtualgl/issues/102

Checked VirtualGL version:

$ rpm -qi VirtualGL
VirtualGL-2.5.2-4.fc31.x86_64

Added original VirtualGL yum repo according to https://virtualgl.org/Downloads/YUM

$ cat /etc/yum.repos.d/VirtualGL.repo 
[VirtualGL]
name=VirtualGL official RPMs
baseurl=https://sourceforge.net/projects/virtualgl/files
gpgcheck=1
gpgkey=https://sourceforge.net/projects/virtualgl/files/VGL-GPG-KEY
enabled=1
exclude=VirtualGL-*.*.9[0-9]-*