dweiss commented on a change in pull request #1126: LUCENE-4702: Terms dictionary compression. URL: https://github.com/apache/lucene-solr/pull/1126#discussion_r362516139
########## File path: lucene/core/src/java/org/apache/lucene/codecs/blocktree/CompressionAlgorithm.java ########## @@ -0,0 +1,93 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.lucene.codecs.blocktree; + +import java.io.IOException; + +import org.apache.lucene.store.DataInput; +import org.apache.lucene.util.compress.LowercaseAsciiCompression; + +/** + * Compression algorithm used for suffixes of a block of terms. + */ +enum CompressionAlgorithm { + + NO_COMPRESSION(0x00) { + + @Override + void read(DataInput in, byte[] out, int len) throws IOException { + in.readBytes(out, 0, len); + } + + @Override + public String toString() { + return "no_compression"; + } + }, + + LOWERCASE_ASCII(0x01) { + + @Override + void read(DataInput in, byte[] out, int len) throws IOException { + LowercaseAsciiCompression.decompress(in, out, len); + } + + @Override + public String toString() { + return "lowercase_ascii"; + } + }, + + LZ4(0x02) { + + @Override + void read(DataInput in, byte[] out, int len) throws IOException { + org.apache.lucene.util.compress.LZ4.decompress(in, len, out, 0); + } + + @Override + public String toString() { + return "lz4"; + } + }; + + private static final CompressionAlgorithm[] BY_CODE = new CompressionAlgorithm[3]; Review comment: You are entitled to your opinion, David. But the comment Adrien made still holds: when you reorder or add/ remove enum constants, their ordinal will change and this side effect is worth guarding against. The "code" may be verbose but it is also explicit and makes making a mistake more difficult. I think it's valuable here. Anyway. My original comment about hardcoded values was only to point out that code used the same constants in different places. I suggested an enum (like Adrien implemented) but it could as well be a set of constant integers declared in one place. I don't care about this (but I do care about using or overriding ordinal()...). ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org For additional commands, e-mail: issues-h...@lucene.apache.org