堆如何知道要排序的内容?(How does Heap know what to sort by?)
如果这个问题听起来含糊不清,我道歉。 我目前使用Javascript来创建一个A *寻路算法。 我有一个对象列表,每个对象都有一个属性f ,我希望使用minheap数据结构对列表进行排序。
我不明白的是如何修改基于排序的内容。 我提到的对象有多个属性,比如h和g 。 有没有我不知道的符号? 我使用npm下载了堆包 。
到目前为止我所拥有的是:
var Heap = require('heap'); var heap = new Heap(); . . . heap.push(start) // start is an object, specifically a Cell inside a grid if(!heap.empty){ // where I am having trouble }
我试图替代的代码(出于性能原因)是:
var winner = 0; for (var i = 0; i < openSet.length; i++) { if (openSet[i].f < openSet[winner].f) { winner = i; } }
我将不胜感激任何指导。 谢谢。
My apologies if this question sounds vague. I am currently using Javascript to create an A* pathfinding algorithm. I have a list of Objects that each have an attribute f and I would like to use the minheap data structure to sort through a list.
What I don't understand is how to modify what to base the sorting on. The Objects I mentioned have multiple attributes, like h and g for instance. Is there a notation that I am not aware of? I downloaded the heap package using npm.
So far what I have is:
var Heap = require('heap'); var heap = new Heap(); . . . heap.push(start) // start is an object, specifically a Cell inside a grid if(!heap.empty){ // where I am having trouble }
And the code I am trying to substitute (for performance reasons) is:
var winner = 0; for (var i = 0; i < openSet.length; i++) { if (openSet[i].f < openSet[winner].f) { winner = i; } }
I would appreciate any guidance. Thank you.
原文:https://stackoverflow.com/questions/47404800
最满意答案
如果您只是要合并结果,可以使用
union
http://dev.mysql.com/doc/refman/5.7/en/union.html(SELECT `Price` FROM `".$this->symbol."Trades` ORDER BY `ts` DESC LIMIT 1) UNION (SELECT `Price` FROM `".$this->symbol."Trades` WHERE `ts` >= DATE_SUB(NOW(), INTERVAL 1 DAY) ORDER BY `ts` ASC LIMIT 1)
if you have just to merge the results, you can use the
union
http://dev.mysql.com/doc/refman/5.7/en/union.html(SELECT `Price` FROM `".$this->symbol."Trades` ORDER BY `ts` DESC LIMIT 1) UNION (SELECT `Price` FROM `".$this->symbol."Trades` WHERE `ts` >= DATE_SUB(NOW(), INTERVAL 1 DAY) ORDER BY `ts` ASC LIMIT 1)
相关问答
更多-
实际上,24小时后就意味着你应该每天增加一天,而不是减去一天。 SELECT * FROM `udflyt` WHERE dato_tid <= DATE_ADD(CURDATE(), INTERVAL +1 day); 将仅提供日期为'2018-07-18'的记录(我相信,这正是您所寻找的。 下面显示了用于进行加法和减法的比较的值。 SELECT *, DATE_ADD(CURDATE(), INTERVAL +1 day), DATE_ADD(CURDATE(), INTERVAL -1 day) ...
-
SELECT * FROM table_name WHERE table_name.the_date > DATE_SUB(CURDATE(), INTERVAL 1 DAY) SELECT * FROM table_name WHERE table_name.the_date > DATE_SUB(CURDATE(), INTERVAL 1 DAY)
-
您目前有PHP 和 MySQL语法错误,因为您的结束括号是结束双引号的错误一面。 如下所示,列大于或等于现在减去1天: $result = $db->query(" SELECT reclamations.* , customers.* FROM reclamations LEFT JOIN customers ON reclamations.id_customer = customers.id ORDER BY reclamations.code ...
-
MySql 24小时间隔选择(MySql 24 hours intervals select)[2023-08-05]
使用以下SQL查询: SELECT *, TIMESTAMPADD(HOUR, 12, DATE(TIMESTAMPADD(HOUR, -12, created))) AS grp FROM table ORDER BY created DESC 这会将最新添加的用户放在首位。 如果您希望最老的用户位于最前面,您可以将DESC更改为ASC 。 另外,我添加的是一个grp专栏。 它将帮助您在PHP中使用分组。 该列的结果是August, 24 2013 12:00:00+0000 。 每当此值更改时,您需要 ... -
您可以使用between关键字 select * from `ordermaster` where `Pick_date` = curdate() and `Pick_time` between (now() - interval 2 hour) and now() and `Status` = 2 编辑 根据我们的聊天,在我们发现GoDaddy服务器的情况下,您的数据库托管时间比当地时间早12.5小时,因此您应该使用的最终查询是 select * from ...
-
脱离我的头脑......(MYSQL) declare @endTime datetime; select @endTime=timestamp from data where id=@rowId select * from data where timestamp<=@endtime and timestamp>ADDDATE(@endTime,INTERVAL -1 DAY) (T-SQL) declare @endTime datetime2; select @en ...
-
如果您只是要合并结果,可以使用union http://dev.mysql.com/doc/refman/5.7/en/union.html (SELECT `Price` FROM `".$this->symbol."Trades` ORDER BY `ts` DESC LIMIT 1) UNION (SELECT `Price` FROM `".$this->symbol."Trades` WHERE `ts` >= DATE_SUB(NOW(), INTERVAL 1 DAY) ORDER BY ...
-
插入最新的行(getting the newest row inserted)[2023-09-25]
使用LIMIT : $stmt = $db->query('SELECT * FROM posts ORDER BY date DESC LIMIT 1'); $row = $stmt->fetch(); // fetch the most recent single record $itemtop = $row['date']; // ...and whatever other columns you want Use LIMIT: $stmt = $db->query('SELECT * FROM ... -
使用min窗口功能。 select datetimecol,value from ( select t.*,min(datetimecol) over(partition by cast(datetimecol as date),datepart(hour,datetimecol)) mintmstmp from tablename t ) x where datetimecol=mintmstmp 编辑1:要获得给定日期特定小时的最接近值,请使用 select top 1 datetimecol,va ...
-
选择具有最接近时间戳的行(Select rows with closest timestamp)[2023-10-17]
您可以尝试这样做: 首先创建一个time_intervals列表。 使用存储过程make_intervals来获取两个日期之间的日期列表创建一个临时表,以某种方式调用它: call make_intervals(@startdate,@enddate,15,'SECOND'); 然后,您将拥有一个表time_intervals ,其中包含名为interval_start的两列之一。 使用它来查找每个间隔最接近的时间戳,如下所示: CREATE TEMPORARY TABLE IF NOT EXISTS t ...