{"action":"created","issue":{"url":"https://api.github.com/repos/decisionpatterns/r-hash/issues/15","repository_url":"https://api.github.com/repos/decisionpatterns/r-hash","labels_url":"https://api.github.com/repos/decisionpatterns/r-hash/issues/15/labels{/name}","comments_url":"https://api.github.com/repos/decisionpatterns/r-hash/issues/15/comments","events_url":"https://api.github.com/repos/decisionpatterns/r-hash/issues/15/events","html_url":"https://github.com/decisionpatterns/r-hash/issues/15","id":186486062,"number":15,"title":"Improve Performance by Unsorted return and documentation improvements","user":{"login":"fangly","id":231905,"avatar_url":"https://avatars.githubusercontent.com/u/231905?v=3","gravatar_id":"","url":"https://api.github.com/users/fangly","html_url":"https://github.com/fangly","followers_url":"https://api.github.com/users/fangly/followers","following_url":"https://api.github.com/users/fangly/following{/other_user}","gists_url":"https://api.github.com/users/fangly/gists{/gist_id}","starred_url":"https://api.github.com/users/fangly/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fangly/subscriptions","organizations_url":"https://api.github.com/users/fangly/orgs","repos_url":"https://api.github.com/users/fangly/repos","events_url":"https://api.github.com/users/fangly/events{/privacy}","received_events_url":"https://api.github.com/users/fangly/received_events","type":"User","site_admin":false},"labels":[{"id":68564189,"url":"https://api.github.com/repos/decisionpatterns/r-hash/labels/enhancement","name":"enhancement","color":"84b6eb","default":true},{"id":68564191,"url":"https://api.github.com/repos/decisionpatterns/r-hash/labels/question","name":"question","color":"cc317c","default":true}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2016-11-01T08:54:45Z","updated_at":"2016-12-05T09:39:11Z","closed_at":null,"body":"Hi Chris,\r\n\r\nI was wondering if the values returned by ```keys()``` and ```values()``` are ordered by time of insertion or in an arbitrary order. I looked at the ```hash``` documentation but found no hint about their order. I then looked at the code and discovered that the order depends on a call to ```ls()```. A quick look at the manpage for ```ls()``` tells me that the output is sorted alphabetically by default (which is what ```keys()``` uses), and that this naturally incurs a time penalty. Thus, I would suggest a few things:\r\n\r\n1. hash is performance-oriented. For the sake of performance, add ```sorted=FALSE``` to the ```ls()``` call in the ```keys()``` function. I do not think there would be an overwhelming interest in having the keys sorted alphabetically and those who may need this feature occasionally can still easily do it themselves with a call to ```sort()```.\r\n1. In the documentation for ```keys()```, add that the order of the returned keys is arbitrary.\r\n1. In the documentation for ```values()```, add that the order of the returned values is guaranteed to be the same as keys().\r\n\r\nBest,\r\n\r\nFlorent\r\n\r\nPS/ Let me know how I can help further with this."},"comment":{"url":"https://api.github.com/repos/decisionpatterns/r-hash/issues/comments/264807683","html_url":"https://github.com/decisionpatterns/r-hash/issues/15#issuecomment-264807683","issue_url":"https://api.github.com/repos/decisionpatterns/r-hash/issues/15","id":264807683,"user":{"login":"fangly","id":231905,"avatar_url":"https://avatars.githubusercontent.com/u/231905?v=3","gravatar_id":"","url":"https://api.github.com/users/fangly","html_url":"https://github.com/fangly","followers_url":"https://api.github.com/users/fangly/followers","following_url":"https://api.github.com/users/fangly/following{/other_user}","gists_url":"https://api.github.com/users/fangly/gists{/gist_id}","starred_url":"https://api.github.com/users/fangly/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fangly/subscriptions","organizations_url":"https://api.github.com/users/fangly/orgs","repos_url":"https://api.github.com/users/fangly/repos","events_url":"https://api.github.com/users/fangly/events{/privacy}","received_events_url":"https://api.github.com/users/fangly/received_events","type":"User","site_admin":false},"created_at":"2016-12-05T09:39:11Z","updated_at":"2016-12-05T09:39:11Z","body":"Hi Chris,\r\n\r\nObviously, this issue is not high priority and can wait. However, I saw that you are almost ready for a release and I would **really like** if you could proceed with it, since **the last version of _hash_ on CRAN is very old (version 2.2.6, 2013)** and I am waiting for this to migrate to the 3.x.x series.\r\n\r\nWhen you find the time to integrate my current enhancement request in _hash_, you can use these expectations that will allow the convenient testing of hashes and unsorted (named) lists :\r\n```\r\nsetdiff_msg <- function(actual, expected, what=\"Values\") {\r\n  if (is.null(actual)) {\r\n    actual <- list()\r\n  }\r\n  if (is.null(expected)) {\r\n    expected <- list()\r\n  }\r\n  diff <- setdiff(actual, expected)\r\n  if (length(diff)) {\r\n    sprintf(\"%s not equal. First difference was: %s\", what, diff[[1]])\r\n  } else {\r\n    \"\"\r\n  }\r\n}\r\n\r\nexpect_sets_equal <- function(actual, expected) {\r\n  names_actual   <- names(actual)\r\n  names_expected <- names(expected)\r\n  if (length(names_actual) || length(names_expected)) {\r\n    # compare set of names, then sorted sequence of corresponding values\r\n    msg <- setdiff_msg(names_actual, names_expected, what=\"Names\")\r\n    expect(!nzchar(msg), msg)\r\n    expect_equal(actual[names_actual], expected[names_actual], info=\"Values not equal\")\r\n  } else {\r\n    # no names present, compare set of values only\r\n    msg <- setdiff_msg(actual, expected)\r\n    expect(!nzchar(msg), msg)\r\n  }\r\n  invisible(actual)\r\n}\r\n\r\nexpect_hashes_equal <- function(actual, expected) {\r\n  expect_sets_equal(values(actual), values(expected))\r\n  # keys are also tested (present as names in the list reported by values()).\r\n}\r\n\r\nh1 <- hash(1:3, 4:6)\r\nh2 <- hash(1:3, c(4,4,6))\r\n\r\n\r\nexpect_sets_equal(keys(h1),keys(h1))\r\nexpect_sets_equal(keys(h1),keys(h2))\r\n\r\nexpect_sets_equal(values(h1),values(h1))\r\nexpect_sets_equal(values(h1),values(h2))\r\n\r\nexpect_hashes_equal(h1, h1)\r\nexpect_hashes_equal(h1, h2)\r\n```\r\n\r\nThank you! Best,\r\n\r\nFlorent\r\n\r\n"}}
{"actor":{"display_login":"fangly"}}