Skip to content

Commit

Permalink
[py] PriorityQueue.
Browse files Browse the repository at this point in the history
  • Loading branch information
pfusik committed Nov 7, 2024
1 parent ea99e32 commit ab0c5ae
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 1 deletion.
19 changes: 19 additions & 0 deletions GenPy.fu
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,9 @@ public class GenPy : GenPySwift
Include("collections");
WriteCollectionTypeAnnotation("collections.deque", klass);
break;
case FuId.PriorityQueueClass:
WriteCollectionTypeAnnotation("list", klass);
break;
case FuId.HashSetClass:
case FuId.SortedSetClass:
WriteCollectionTypeAnnotation("set", klass);
Expand Down Expand Up @@ -483,6 +486,7 @@ public class GenPy : GenPySwift
case FuId.ListCount:
case FuId.QueueCount:
case FuId.StackCount:
case FuId.PriorityQueueCount:
case FuId.HashSetCount:
case FuId.SortedSetCount:
case FuId.DictionaryCount:
Expand Down Expand Up @@ -708,6 +712,9 @@ public class GenPy : GenPySwift
Include("collections");
Write("collections.deque()");
break;
case FuId.PriorityQueueClass:
Write("[]");
break;
case FuId.HashSetClass:
case FuId.SortedSetClass:
Write("set()");
Expand Down Expand Up @@ -961,8 +968,20 @@ public class GenPy : GenPySwift
WriteListAppend(obj, args);
break;
case FuId.QueuePeek:
case FuId.PriorityQueuePeek:
WritePostfix(obj, "[0]");
break;
case FuId.PriorityQueueClear:
WritePostfix(obj, ".clear()");
break;
case FuId.PriorityQueueEnqueue:
Include("heapq");
WriteCall("heapq.heappush", obj, args[0]);
break;
case FuId.PriorityQueueDequeue:
Include("heapq");
WriteCall("heapq.heappop", obj);
break;
case FuId.DictionaryAdd:
WriteDictionaryAdd(obj, args);
break;
Expand Down
19 changes: 19 additions & 0 deletions libfut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23587,6 +23587,9 @@ void GenPy::writeTypeAnnotation(const FuType * type, bool nullable)
include("collections");
writeCollectionTypeAnnotation("collections.deque", klass);
break;
case FuId::priorityQueueClass:
writeCollectionTypeAnnotation("list", klass);
break;
case FuId::hashSetClass:
case FuId::sortedSetClass:
writeCollectionTypeAnnotation("set", klass);
Expand Down Expand Up @@ -23755,6 +23758,7 @@ void GenPy::visitSymbolReference(const FuSymbolReference * expr, FuPriority pare
case FuId::listCount:
case FuId::queueCount:
case FuId::stackCount:
case FuId::priorityQueueCount:
case FuId::hashSetCount:
case FuId::sortedSetCount:
case FuId::dictionaryCount:
Expand Down Expand Up @@ -23978,6 +23982,9 @@ void GenPy::writeNew(const FuReadWriteClassType * klass, FuPriority parent)
include("collections");
write("collections.deque()");
break;
case FuId::priorityQueueClass:
write("[]");
break;
case FuId::hashSetClass:
case FuId::sortedSetClass:
write("set()");
Expand Down Expand Up @@ -24234,8 +24241,20 @@ void GenPy::writeCallExpr(const FuExpr * obj, const FuMethod * method, const std
writeListAppend(obj, args);
break;
case FuId::queuePeek:
case FuId::priorityQueuePeek:
writePostfix(obj, "[0]");
break;
case FuId::priorityQueueClear:
writePostfix(obj, ".clear()");
break;
case FuId::priorityQueueEnqueue:
include("heapq");
writeCall("heapq.heappush", obj, (*args)[0].get());
break;
case FuId::priorityQueueDequeue:
include("heapq");
writeCall("heapq.heappop", obj);
break;
case FuId::dictionaryAdd:
writeDictionaryAdd(obj, args);
break;
Expand Down
19 changes: 19 additions & 0 deletions libfut.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24441,6 +24441,9 @@ void WriteTypeAnnotation(FuType type, bool nullable = false)
Include("collections");
WriteCollectionTypeAnnotation("collections.deque", klass);
break;
case FuId.PriorityQueueClass:
WriteCollectionTypeAnnotation("list", klass);
break;
case FuId.HashSetClass:
case FuId.SortedSetClass:
WriteCollectionTypeAnnotation("set", klass);
Expand Down Expand Up @@ -24606,6 +24609,7 @@ internal override void VisitSymbolReference(FuSymbolReference expr, FuPriority p
case FuId.ListCount:
case FuId.QueueCount:
case FuId.StackCount:
case FuId.PriorityQueueCount:
case FuId.HashSetCount:
case FuId.SortedSetCount:
case FuId.DictionaryCount:
Expand Down Expand Up @@ -24826,6 +24830,9 @@ protected override void WriteNew(FuReadWriteClassType klass, FuPriority parent)
Include("collections");
Write("collections.deque()");
break;
case FuId.PriorityQueueClass:
Write("[]");
break;
case FuId.HashSetClass:
case FuId.SortedSetClass:
Write("set()");
Expand Down Expand Up @@ -25079,8 +25086,20 @@ protected override void WriteCallExpr(FuExpr obj, FuMethod method, List<FuExpr>
WriteListAppend(obj, args);
break;
case FuId.QueuePeek:
case FuId.PriorityQueuePeek:
WritePostfix(obj, "[0]");
break;
case FuId.PriorityQueueClear:
WritePostfix(obj, ".clear()");
break;
case FuId.PriorityQueueEnqueue:
Include("heapq");
WriteCall("heapq.heappush", obj, args[0]);
break;
case FuId.PriorityQueueDequeue:
Include("heapq");
WriteCall("heapq.heappop", obj);
break;
case FuId.DictionaryAdd:
WriteDictionaryAdd(obj, args);
break;
Expand Down
19 changes: 19 additions & 0 deletions libfut.js
Original file line number Diff line number Diff line change
Expand Up @@ -25091,6 +25091,9 @@ export class GenPy extends GenPySwift
this.include("collections");
this.#writeCollectionTypeAnnotation("collections.deque", klass);
break;
case FuId.PRIORITY_QUEUE_CLASS:
this.#writeCollectionTypeAnnotation("list", klass);
break;
case FuId.HASH_SET_CLASS:
case FuId.SORTED_SET_CLASS:
this.#writeCollectionTypeAnnotation("set", klass);
Expand Down Expand Up @@ -25260,6 +25263,7 @@ export class GenPy extends GenPySwift
case FuId.LIST_COUNT:
case FuId.QUEUE_COUNT:
case FuId.STACK_COUNT:
case FuId.PRIORITY_QUEUE_COUNT:
case FuId.HASH_SET_COUNT:
case FuId.SORTED_SET_COUNT:
case FuId.DICTIONARY_COUNT:
Expand Down Expand Up @@ -25488,6 +25492,9 @@ export class GenPy extends GenPySwift
this.include("collections");
this.write("collections.deque()");
break;
case FuId.PRIORITY_QUEUE_CLASS:
this.write("[]");
break;
case FuId.HASH_SET_CLASS:
case FuId.SORTED_SET_CLASS:
this.write("set()");
Expand Down Expand Up @@ -25742,8 +25749,20 @@ export class GenPy extends GenPySwift
this.writeListAppend(obj, args);
break;
case FuId.QUEUE_PEEK:
case FuId.PRIORITY_QUEUE_PEEK:
this.writePostfix(obj, "[0]");
break;
case FuId.PRIORITY_QUEUE_CLEAR:
this.writePostfix(obj, ".clear()");
break;
case FuId.PRIORITY_QUEUE_ENQUEUE:
this.include("heapq");
this.writeCall("heapq.heappush", obj, args[0]);
break;
case FuId.PRIORITY_QUEUE_DEQUEUE:
this.include("heapq");
this.writeCall("heapq.heappop", obj);
break;
case FuId.DICTIONARY_ADD:
this.writeDictionaryAdd(obj, args);
break;
Expand Down
2 changes: 1 addition & 1 deletion test/PriorityQueue.fu
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ public static class Test
{
public static bool Run()
{
PriorityQueue<int>() q; //FAIL: d js py swift ts TODO; c, cl
PriorityQueue<int>() q; //FAIL: d js swift ts TODO; c, cl
q.Enqueue(42);
q.Clear();
q.Enqueue(15);
Expand Down

0 comments on commit ab0c5ae

Please sign in to comment.