Commit 8abed585 authored by amir.yosef's avatar amir.yosef

disabling vector api

parent a87b5250
......@@ -2,6 +2,5 @@
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
<mapping directory="$PROJECT_DIR$/key_value-server" vcs="Git" />
</component>
</project>
\ No newline at end of file
......@@ -16,10 +16,10 @@ public class SetCommand implements CommandHandler {
public void execute(List<String> commands, OutputStream os) {
Map<String, String> commandsMap = new HashMap<>();
//
// for (int i = 2; i < commands.size(); i += 2) {
// commandsMap.put(commands.get(i).toLowerCase(), commands.get(i + 1));
// }
for (int i = 2; i < commands.size(); i += 2) {
commandsMap.put(commands.get(i).toLowerCase(), commands.get(i + 1));
}
String value = commands.get(2);
......
......@@ -9,7 +9,6 @@ import util.CommandUtil;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Arrays;
import java.util.List;
public class ClientCommandHandler {
......@@ -24,11 +23,12 @@ public class ClientCommandHandler {
public boolean execute() {
Command command = CommandUtil.getCommand(commands.getFirst().split(" ")[0]);
Command command = CommandUtil.getCommand(commands.getFirst());
System.out.println(command);
System.out.println("Command " + commands);
CommandHandler commandProcessor = new CommandFactory(command).getInstance();
List<String> commandAndArgs = Arrays.stream(commands.getFirst().split(" ")).toList();
try {
CommandInvoker.invoke(commandProcessor, commandAndArgs, os);
CommandInvoker.invoke(commandProcessor, commands, os);
} catch (IOException e) {
throw new RuntimeException(e);
}
......
package storage;
import jdk.incubator.vector.ByteVector;
import jdk.incubator.vector.VectorMask;
import jdk.incubator.vector.VectorOperators;
import jdk.incubator.vector.VectorSpecies;
//
//import jdk.incubator.vector.ByteVector;
//import jdk.incubator.vector.VectorMask;
//import jdk.incubator.vector.VectorOperators;
//import jdk.incubator.vector.VectorSpecies;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
......@@ -13,7 +13,7 @@ public class Storage {
private final Map<String, Long> timeToExpiration = new ConcurrentHashMap<>(10000);
private final Map<String, Long> currentTimeForKey = new ConcurrentHashMap<>(10000);
private static final VectorSpecies<Byte> SPECIES = ByteVector.SPECIES_128;
//private static final VectorSpecies<Byte> SPECIES = ByteVector.SPECIES_128;
private Storage() {
// RdbFileReader reader = new RdbFileReader();
......@@ -45,44 +45,44 @@ public class Storage {
public String get(String key) {
System.out.println("GET Storage: " + key);
if (isExpired(key)) {
System.out.println("Key expired: " + key);
return "";
}
// if (isExpired(key)) {
// System.out.println("Key expired: " + key);
// return "";
// }
return storage.get(key);
}
private boolean isExpired(String key) {
long currentTime = System.currentTimeMillis();
if (timeToExpiration.containsKey(key)) {
long expirationTime = timeToExpiration.get(key);
if (currentTimeForKey.containsKey(key)) {
long currExpiration = currentTimeForKey.get(key);
long timeDiff = currentTime - currExpiration;
return vectorizedComparison(timeDiff, expirationTime);
} else {
return vectorizedComparison(currentTime, expirationTime);
}
}
return false;
}
private boolean vectorizedComparison(long timeDiff, long expirationTime) {
// Convert timeDiff and expirationTime to byte arrays for SIMD processing
byte[] timeDiffBytes = longToBytes(timeDiff);
byte[] expirationTimeBytes = longToBytes(expirationTime);
ByteVector timeDiffVector = ByteVector.fromArray(SPECIES, timeDiffBytes, 0);
ByteVector expirationTimeVector = ByteVector.fromArray(SPECIES, expirationTimeBytes, 0);
VectorMask<Byte> mask = timeDiffVector.compare(VectorOperators.GT, expirationTimeVector);
return mask.anyTrue();
}
//
// private boolean isExpired(String key) {
// long currentTime = System.currentTimeMillis();
//
// if (timeToExpiration.containsKey(key)) {
// long expirationTime = timeToExpiration.get(key);
//
// if (currentTimeForKey.containsKey(key)) {
// long currExpiration = currentTimeForKey.get(key);
// long timeDiff = currentTime - currExpiration;
// return vectorizedComparison(timeDiff, expirationTime);
// } else {
// return vectorizedComparison(currentTime, expirationTime);
// }
// }
// return false;
// }
// private boolean vectorizedComparison(long timeDiff, long expirationTime) {
// // Convert timeDiff and expirationTime to byte arrays for SIMD processing
// byte[] timeDiffBytes = longToBytes(timeDiff);
// byte[] expirationTimeBytes = longToBytes(expirationTime);
//
// ByteVector timeDiffVector = ByteVector.fromArray(SPECIES, timeDiffBytes, 0);
// ByteVector expirationTimeVector = ByteVector.fromArray(SPECIES, expirationTimeBytes, 0);
//
//
// VectorMask<Byte> mask = timeDiffVector.compare(VectorOperators.GT, expirationTimeVector);
//
// return mask.anyTrue();
// }
private byte[] longToBytes(long value) {
byte[] bytes = new byte[8];
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment