java/core/src/main/java/se/lth/cs/docria/Text.java
/**
     * Based on ref counts, compacts and assigns id to offsets
     */
Based on ref counts, compacts and assigns id to offsets
Based on ref counts compacts and assigns id to offsets
protected List<String> compile() {
        int id = 0;
        {
            IntArrayList removal = new IntArrayList();
            pos2Offset.values().stream().filter(off -> off.refcount == 0).mapToInt(off -> off.offset).forEach(removal::add);
            IntListIterator iter = removal.iterator();
            while (iter.hasNext()) {
                pos2Offset.remove(iter.nextInt());
            }
        }
        IntAVLTreeSet sortedSet = new IntAVLTreeSet(pos2Offset.keySet());
        if(!sortedSet.contains(0)){
            Offset start = new Offset(0);
            pos2Offset.put(0, start);
            sortedSet.add(0);
        }
        if(!sortedSet.contains(text.length())) {
            Offset stop = new Offset(text.length());
            pos2Offset.put(text.length(), stop);
            sortedSet.add(text.length());
        }
        List<String> positions = new ArrayList<>();
        if(sortedSet.size() == 1) {
            positions.add("");
        }
        else
        {
            IntBidirectionalIterator iter = sortedSet.iterator();
            int startOffset = iter.nextInt();
            pos2Offset.get(startOffset).id = id++;
            do {
                int stopOffset = iter.nextInt();
                pos2Offset.get(stopOffset).id = id++;
                positions.add(text.substring(startOffset, stopOffset));
                startOffset = stopOffset;
            } while (iter.hasNext());
        }
        return positions;
    }
protected List < String > compile ( ) { int id = 0 ; { IntArrayList removal = new IntArrayList ( ) ; pos2Offset . values ( ) . stream ( ) . filter ( off -> off . refcount == 0 ) . mapToInt ( off -> off . offset ) . forEach ( removal :: add ) ; IntListIterator iter = removal . iterator ( ) ; while ( iter . hasNext ( ) ) { pos2Offset . remove ( iter . nextInt ( ) ) ; } } IntAVLTreeSet sortedSet = new IntAVLTreeSet ( pos2Offset . keySet ( ) ) ; if ( ! sortedSet . contains ( 0 ) ) { Offset start = new Offset ( 0 ) ; pos2Offset . put ( 0 , start ) ; sortedSet . add ( 0 ) ; } if ( ! sortedSet . contains ( text . length ( ) ) ) { Offset stop = new Offset ( text . length ( ) ) ; pos2Offset . put ( text . length ( ) , stop ) ; sortedSet . add ( text . length ( ) ) ; } List < String > positions = new ArrayList < > ( ) ; if ( sortedSet . size ( ) == 1 ) { positions . add ( "" ) ; } else { IntBidirectionalIterator iter = sortedSet . iterator ( ) ; int startOffset = iter . nextInt ( ) ; pos2Offset . get ( startOffset ) . id = id ++ ; do { int stopOffset = iter . nextInt ( ) ; pos2Offset . get ( stopOffset ) . id = id ++ ; positions . add ( text . substring ( startOffset , stopOffset ) ) ; startOffset = stopOffset ; } while ( iter . hasNext ( ) ) ; } return positions ; }
Based on ref counts, compacts and assigns id to offsets
Based on ref counts compacts and assigns id to offsets
//Occurs when string is of length 0