classOrderManagementSystem:def__init__(self):self.orders={}self.t=defaultdict(list)defaddOrder(self,orderId:int,orderType:str,price:int)->None:self.orders[orderId]=(orderType,price)self.t[(orderType,price)].append(orderId)defmodifyOrder(self,orderId:int,newPrice:int)->None:orderType,price=self.orders[orderId]self.orders[orderId]=(orderType,newPrice)self.t[(orderType,price)].remove(orderId)self.t[(orderType,newPrice)].append(orderId)defcancelOrder(self,orderId:int)->None:orderType,price=self.orders[orderId]delself.orders[orderId]self.t[(orderType,price)].remove(orderId)defgetOrdersAtPrice(self,orderType:str,price:int)->List[int]:returnself.t[(orderType,price)]# Your OrderManagementSystem object will be instantiated and called as such:# obj = OrderManagementSystem()# obj.addOrder(orderId,orderType,price)# obj.modifyOrder(orderId,newPrice)# obj.cancelOrder(orderId)# param_4 = obj.getOrdersAtPrice(orderType,price)
classOrderManagementSystem{privaterecordKey(StringorderType,intprice){}privatefinalMap<Integer,String>orderTypeMap;privatefinalMap<Integer,Integer>priceMap;privatefinalMap<Key,List<Integer>>t;publicOrderManagementSystem(){orderTypeMap=newHashMap<>();priceMap=newHashMap<>();t=newHashMap<>();}publicvoidaddOrder(intorderId,StringorderType,intprice){orderTypeMap.put(orderId,orderType);priceMap.put(orderId,price);varkey=newKey(orderType,price);t.computeIfAbsent(key,_->newArrayList<>()).add(orderId);}publicvoidmodifyOrder(intorderId,intnewPrice){varorderType=orderTypeMap.get(orderId);varoldPrice=priceMap.get(orderId);priceMap.put(orderId,newPrice);t.get(newKey(orderType,oldPrice)).remove((Integer)orderId);t.computeIfAbsent(newKey(orderType,newPrice),_->newArrayList<>()).add(orderId);}publicvoidcancelOrder(intorderId){varorderType=orderTypeMap.remove(orderId);varprice=priceMap.remove(orderId);t.get(newKey(orderType,price)).remove((Integer)orderId);}publicint[]getOrdersAtPrice(StringorderType,intprice){varlist=t.getOrDefault(newKey(orderType,price),List.of());returnlist.stream().mapToInt(Integer::intValue).toArray();}}/** * Your OrderManagementSystem object will be instantiated and called as such: * OrderManagementSystem obj = new OrderManagementSystem(); * obj.addOrder(orderId,orderType,price); * obj.modifyOrder(orderId,newPrice); * obj.cancelOrder(orderId); * int[] param_4 = obj.getOrdersAtPrice(orderType,price); */
classOrderManagementSystem{usingKey=pair<string,int>;structKeyHash{size_toperator()(constKey&k)const{returnhash<string>()(k.first)^(hash<int>()(k.second)<<1);}};unordered_map<int,string>orderTypeMap;unordered_map<int,int>priceMap;unordered_map<Key,vector<int>,KeyHash>t;public:OrderManagementSystem(){}voidaddOrder(intorderId,stringorderType,intprice){orderTypeMap[orderId]=orderType;priceMap[orderId]=price;t[{orderType,price}].push_back(orderId);}voidmodifyOrder(intorderId,intnewPrice){stringorderType=orderTypeMap[orderId];intoldPrice=priceMap[orderId];priceMap[orderId]=newPrice;auto&oldList=t[{orderType,oldPrice}];oldList.erase(find(oldList.begin(),oldList.end(),orderId));t[{orderType,newPrice}].push_back(orderId);}voidcancelOrder(intorderId){stringorderType=orderTypeMap[orderId];intprice=priceMap[orderId];orderTypeMap.erase(orderId);priceMap.erase(orderId);auto&list=t[{orderType,price}];list.erase(find(list.begin(),list.end(),orderId));}vector<int>getOrdersAtPrice(stringorderType,intprice){autoit=t.find({orderType,price});if(it==t.end())return{};returnit->second;}};/** * Your OrderManagementSystem object will be instantiated and called as such: * OrderManagementSystem* obj = new OrderManagementSystem(); * obj->addOrder(orderId,orderType,price); * obj->modifyOrder(orderId,newPrice); * obj->cancelOrder(orderId); * vector<int> param_4 = obj->getOrdersAtPrice(orderType,price); */
typeKeystruct{orderTypestringpriceint}typeOrderManagementSystemstruct{orderTypeMapmap[int]stringpriceMapmap[int]inttmap[Key][]int}funcConstructor()OrderManagementSystem{returnOrderManagementSystem{orderTypeMap:make(map[int]string),priceMap:make(map[int]int),t:make(map[Key][]int),}}func(this*OrderManagementSystem)AddOrder(orderIdint,orderTypestring,priceint){this.orderTypeMap[orderId]=orderTypethis.priceMap[orderId]=pricekey:=Key{orderType,price}this.t[key]=append(this.t[key],orderId)}func(this*OrderManagementSystem)ModifyOrder(orderIdint,newPriceint){orderType:=this.orderTypeMap[orderId]oldPrice:=this.priceMap[orderId]this.priceMap[orderId]=newPriceoldKey:=Key{orderType,oldPrice}oldList:=this.t[oldKey]fori,v:=rangeoldList{ifv==orderId{this.t[oldKey]=append(oldList[:i],oldList[i+1:]...)break}}newKey:=Key{orderType,newPrice}this.t[newKey]=append(this.t[newKey],orderId)}func(this*OrderManagementSystem)CancelOrder(orderIdint){orderType:=this.orderTypeMap[orderId]price:=this.priceMap[orderId]delete(this.orderTypeMap,orderId)delete(this.priceMap,orderId)key:=Key{orderType,price}list:=this.t[key]fori,v:=rangelist{ifv==orderId{this.t[key]=append(list[:i],list[i+1:]...)break}}}func(this*OrderManagementSystem)GetOrdersAtPrice(orderTypestring,priceint)[]int{key:=Key{orderType,price}returnthis.t[key]}/** * Your OrderManagementSystem object will be instantiated and called as such: * obj := Constructor(); * obj.AddOrder(orderId,orderType,price); * obj.ModifyOrder(orderId,newPrice); * obj.CancelOrder(orderId); * param_4 := obj.GetOrdersAtPrice(orderType,price); */
classOrderManagementSystem{privateorderTypeMap:Map<number,string>;privatepriceMap:Map<number,number>;privatet:Map<string,number[]>;constructor(){this.orderTypeMap=newMap();this.priceMap=newMap();this.t=newMap();}privatekey(orderType:string,price:number):string{return`${orderType}#${price}`;}addOrder(orderId:number,orderType:string,price:number):void{this.orderTypeMap.set(orderId,orderType);this.priceMap.set(orderId,price);constk=this.key(orderType,price);if(!this.t.has(k)){this.t.set(k,[]);}this.t.get(k)!.push(orderId);}modifyOrder(orderId:number,newPrice:number):void{constorderType=this.orderTypeMap.get(orderId)!;constoldPrice=this.priceMap.get(orderId)!;this.priceMap.set(orderId,newPrice);constoldKey=this.key(orderType,oldPrice);constoldList=this.t.get(oldKey)!;constidx=oldList.indexOf(orderId);if(idx!==-1){oldList.splice(idx,1);}constnewKey=this.key(orderType,newPrice);if(!this.t.has(newKey)){this.t.set(newKey,[]);}this.t.get(newKey)!.push(orderId);}cancelOrder(orderId:number):void{constorderType=this.orderTypeMap.get(orderId)!;constprice=this.priceMap.get(orderId)!;this.orderTypeMap.delete(orderId);this.priceMap.delete(orderId);constk=this.key(orderType,price);constlist=this.t.get(k)!;constidx=list.indexOf(orderId);if(idx!==-1){list.splice(idx,1);}}getOrdersAtPrice(orderType:string,price:number):number[]{returnthis.t.get(this.key(orderType,price))??[];}}/** * Your OrderManagementSystem object will be instantiated and called as such: * var obj = new OrderManagementSystem() * obj.addOrder(orderId,orderType,price) * obj.modifyOrder(orderId,newPrice) * obj.cancelOrder(orderId) * var param_4 = obj.getOrdersAtPrice(orderType,price) */
usestd::collections::HashMap;structOrderManagementSystem{orders:HashMap<i32,(String,i32)>,t:HashMap<(String,i32),Vec<i32>>,}implOrderManagementSystem{fnnew()->Self{Self{orders:HashMap::new(),t:HashMap::new(),}}fnadd_order(&mutself,order_id:i32,order_type:String,price:i32){self.orders.insert(order_id,(order_type.clone(),price));self.t.entry((order_type,price)).or_insert_with(Vec::new).push(order_id);}fnmodify_order(&mutself,order_id:i32,new_price:i32){ifletSome((order_type,old_price))=self.orders.get(&order_id).cloned(){self.orders.insert(order_id,(order_type.clone(),new_price));ifletSome(v)=self.t.get_mut(&(order_type.clone(),old_price)){ifletSome(pos)=v.iter().position(|&x|x==order_id){v.remove(pos);}}self.t.entry((order_type,new_price)).or_insert_with(Vec::new).push(order_id);}}fncancel_order(&mutself,order_id:i32){ifletSome((order_type,price))=self.orders.remove(&order_id){ifletSome(v)=self.t.get_mut(&(order_type,price)){ifletSome(pos)=v.iter().position(|&x|x==order_id){v.remove(pos);}}}}fnget_orders_at_price(&self,order_type:String,price:i32)->Vec<i32>{self.t.get(&(order_type,price)).cloned().unwrap_or_default()}}/** * Your OrderManagementSystem object will be instantiated and called as such: * let obj = OrderManagementSystem::new(); * obj.add_order(orderId, orderType, price); * obj.modify_order(orderId, newPrice); * obj.cancel_order(orderId); * let ret_4: Vec<i32> = obj.get_orders_at_price(orderType, price); */