{"action":"created","issue":{"url":"https://api.github.com/repos/vigna/Sux4J/issues/2","repository_url":"https://api.github.com/repos/vigna/Sux4J","labels_url":"https://api.github.com/repos/vigna/Sux4J/issues/2/labels{/name}","comments_url":"https://api.github.com/repos/vigna/Sux4J/issues/2/comments","events_url":"https://api.github.com/repos/vigna/Sux4J/issues/2/events","html_url":"https://github.com/vigna/Sux4J/issues/2","id":142950203,"number":2,"title":"GOVMinimalPerfectHashFunction, optimize the call to getLong","user":{"login":"okrische","id":2066544,"avatar_url":"https://avatars.githubusercontent.com/u/2066544?v=3","gravatar_id":"","url":"https://api.github.com/users/okrische","html_url":"https://github.com/okrische","followers_url":"https://api.github.com/users/okrische/followers","following_url":"https://api.github.com/users/okrische/following{/other_user}","gists_url":"https://api.github.com/users/okrische/gists{/gist_id}","starred_url":"https://api.github.com/users/okrische/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/okrische/subscriptions","organizations_url":"https://api.github.com/users/okrische/orgs","repos_url":"https://api.github.com/users/okrische/repos","events_url":"https://api.github.com/users/okrische/events{/privacy}","received_events_url":"https://api.github.com/users/okrische/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2016-03-23T12:44:42Z","updated_at":"2016-03-23T14:40:13Z","closed_at":null,"body":"I use the hash function to create unique hashes for millions of unique keys. Each call to getLong() creates int[3] and long[3], which stresses the GC and could be avoided, imho.\r\n\r\nSo i can use getLongByTriple(long[]), then i have at least the long[3] gone. But it still requires me to subclass the function, so that i get access to the transforming strategy and globalSeed.\r\n\r\nAnd it could be even nicer to have access to getLongByTripleNoCheck(long[], int[]), since i know the keys and do not need the signature check either. But it is a private method.\r\n\r\nSo what could be an alternative? \r\n\r\nI understand, that i need to reset int[] and long[] to 0 with each call. Also you probably want to hide this kind of implementation detail.\r\n\r\nMaybe one can provide another structure, like a buffer,  that has int[] and long[], but is only visible to the function. And one only has to make sure, that this buffer is not shared within different threads.\r\n\r\n```java\r\nGOVBuffer buffer = function.createBuffer();\r\nfor(String key : keys) {\r\n   long hash = function.getLong(key, buffer);\r\n}\r\n\r\npublic class GOVMinimalPerfectHashFunction  ... {\r\n  ...\r\n  public long getLong(T key, GOVBuffer buff) {\r\n       ...\r\n  }\r\n  public static class GOVBuffer {\r\n      private final int[] e = new int[3];\r\n      private final long[] h = new int[3];\r\n      private void reset() {\r\n             int[0] = 0;\r\n             ...\r\n      }\r\n  }\r\n}\r\n```\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/vigna/Sux4J/issues/comments/200374124","html_url":"https://github.com/vigna/Sux4J/issues/2#issuecomment-200374124","issue_url":"https://api.github.com/repos/vigna/Sux4J/issues/2","id":200374124,"user":{"login":"vigna","id":1464942,"avatar_url":"https://avatars.githubusercontent.com/u/1464942?v=3","gravatar_id":"","url":"https://api.github.com/users/vigna","html_url":"https://github.com/vigna","followers_url":"https://api.github.com/users/vigna/followers","following_url":"https://api.github.com/users/vigna/following{/other_user}","gists_url":"https://api.github.com/users/vigna/gists{/gist_id}","starred_url":"https://api.github.com/users/vigna/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vigna/subscriptions","organizations_url":"https://api.github.com/users/vigna/orgs","repos_url":"https://api.github.com/users/vigna/repos","events_url":"https://api.github.com/users/vigna/events{/privacy}","received_events_url":"https://api.github.com/users/vigna/received_events","type":"User","site_admin":false},"created_at":"2016-03-23T14:40:13Z","updated_at":"2016-03-23T14:40:13Z","body":"No, you don't need to reset the arrays—they will be filled with the relevant data.\r\n\r\nI know, the creation of those two arrays is a nuisance. One thing you could do is to have your own subclass that contains those two buffers as attributes. Of course, at that point the class is no longer thread safe, but you can implement a copy() method (as in FlyweightPrototype) that copies by reference the static data and creates a new instance with different buffers.\r\n\r\nI think this approach would be less cumbersome for the caller than having to specify each time a new buffer."}}