int* maxSlidingWindow2(int* nums, int numsSize, int k, int* returnSize) { if (nums == NULL || numsSize == 0) return NULL; Result R; ElementType* Heap; ElementType Node; Queue Q; int i; Q = Initialize(MAX); R = InitializeResult(MAX); Heap = InitHeap(nums, k, Q); BuildHeap(Heap, k); for (i = k; i < numsSize; ++i) { AddToResult(R, Heap[1] -> Value); Node = Dequeue(Q); Node -> Value = nums[i]; Enqueue(Q, Node); AdjustRandItemInHeap(Heap, Node -> Index, k); } AddToResult(R, Heap[1] -> Value); *returnSize = R -> Size; return R -> Next; }
static ContainerHeap *newHeap(size_t ElementSize,const ContainerAllocator *m) { ContainerHeap *result = m->malloc(sizeof(ContainerHeap)); if (result == NULL) return NULL; return InitHeap(result,ElementSize,m); }
void Yap_InitHeap(void *heap_addr) { InitHeap(); Yap_HoleSize = 0; HeapMax = 0; }
inline void FastMarch2D::ReinitHalf() { heapSize = 0; closeSize = 0; SetBoundary(); Initialize(); //PrintFlags(); InitHeap(); FastMarch(); }
void WINAPI SetStartupInfo(const struct PluginStartupInfo *psInfo) { Info = *psInfo; FSF = *psInfo->FSF; Info.FSF = &FSF; InitHeap(); StringCchCopy(PluginRootKey,ARRAYSIZE(PluginRootKey),Info.RootKey); StringCchCat(PluginRootKey,ARRAYSIZE(PluginRootKey),_T("\\UnInstall")); ReadRegistry(); }
main() { struct StrHeap *H; int i; char buf[256]; H = InitHeap(); for (i=1;i<10;i++) { scanf("%s", buf); StringHeap(buf, H); } DisplayStringHeap(H,0,TRUE); }
struct QuantizedValue *FindMatch(uint8 const *sample, int ndims, uint8 *weights, struct QuantizedValue *q) { InitHeap(&TheQueue); struct QuantizedValue *bestmatch=0; double besterror=1.0e63; PUSHNODE(q); for(;;) { struct QuantizedValue *test=(struct QuantizedValue *) RemoveHeapItem(&TheQueue); if (! test) break; // heap empty // printf("got pop node =%p minerror=%f\n",test,test->MinError); if (test->MinError>besterror) break; if (test->Children[0]) { // it's a parent node. put the children on the queue struct QuantizedValue *c1=test->Children[0]; struct QuantizedValue *c2=test->Children[1]; c1->MinError=MinimumError(c1,sample,ndims,weights); if (c1->MinError < besterror) HeapInsert(&TheQueue,&(c1->MinError)); c2->MinError=MinimumError(c2,sample,ndims,weights); if (c2->MinError < besterror) HeapInsert(&TheQueue,&(c2->MinError)); } else { // it's a leaf node. This must be a new minimum or the MinError // test would have failed. if (test->MinError < besterror) { bestmatch=test; besterror=test->MinError; } } } if (bestmatch) { SquaredError+=besterror; bestmatch->NQuant++; for(int i=0;i<ndims;i++) bestmatch->Sums[i]+=sample[i]; } return bestmatch; }
int main() { heap pq; InitHeap(&pq, comp); PushHeap(&pq, 3343, 1, 0); PushHeap(&pq, 13, 1, 0); PushHeap(&pq, 241, 1, 0); PushHeap(&pq, 54, 1, 0); PushHeap(&pq, 2324, 1, 0); PushHeap(&pq, 3, 1, 0); while(!EmptyHeap(&pq)) { printf("%d\n", FrontHeapValue(&pq)); PopHeap(&pq); } ClearHeap(&pq); return 0; }
void InitializeLibrary() { try { // _CrtSetReportMode( _CRT_WARN, _CRTDBG_MODE_DEBUG); // _CrtSetReportMode( _CRT_ERROR, _CRTDBG_MODE_DEBUG); // int iFlags = _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG); // iFlags |= _CRTDBG_CHECK_ALWAYS_DF | _CRTDBG_DELAY_FREE_MEM_DF | _CRTDBG_LEAK_CHECK_DF; // _CrtSetDbgFlag(iFlags); // _CrtSetAllocHook(AllocHook); // for the tab control in customization dialog InitCommonControls(); g_pGlobals = new Globals; assert(g_pGlobals); InitHeap(); } catch (...) { } }
/** This is FRM module entrypoint. @param CommunicationData FRM communication data. @retval RETURN_SUCCESS FRM is launched. @retval RETURN_UNSUPPORTED FRM is unsupproted. **/ RETURN_STATUS _ModuleEntryPoint ( IN FRM_COMMUNICATION_DATA *CommunicationData ) { BOOLEAN InterruptEnabled; if ((AsmReadMsr64 (IA32_FEATURE_CONTROL_MSR_INDEX) & IA32_FEATURE_CONTROL_VMX) == 0) { DEBUG ((EFI_D_ERROR, "(FRM) !!!VMX not enabled!\n")); return RETURN_UNSUPPORTED; } if (mAlreadyEntered) { return FrmS3Entrypoint (); } InterruptEnabled = SaveAndDisableInterrupts (); if (sizeof(UINTN) == sizeof(UINT32)) { DEBUG ((EFI_D_INFO, "(FRM) !!!FrmEntrypoint32!!!\n")); } else { DEBUG ((EFI_D_INFO, "(FRM) !!!FrmEntrypoint64!!!\n")); } DEBUG ((EFI_D_INFO, "(FRM) !!!FRM build time - %a %a!!!\n", (CHAR8 *)__DATE__, (CHAR8 *)__TIME__)); CopyMem (&mCommunicationData, CommunicationData, sizeof(mCommunicationData)); DumpVmxCapabillityMsr (); DEBUG ((EFI_D_INFO, "(FRM) HighMemoryBase - %016lx\n", mCommunicationData.HighMemoryBase)); DEBUG ((EFI_D_INFO, "(FRM) HighMemorySize - %016lx\n", mCommunicationData.HighMemorySize)); DEBUG ((EFI_D_INFO, "(FRM) LowMemoryBase - %016lx\n", mCommunicationData.LowMemoryBase)); DEBUG ((EFI_D_INFO, "(FRM) LowMemorySize - %016lx\n", mCommunicationData.LowMemorySize)); DEBUG ((EFI_D_INFO, "(FRM) ImageBase - %016lx\n", mCommunicationData.ImageBase)); DEBUG ((EFI_D_INFO, "(FRM) ImageSize - %016lx\n", mCommunicationData.ImageSize)); DEBUG ((EFI_D_INFO, "(FRM) TimerPeriod - %016lx\n", mCommunicationData.TimerPeriod)); DEBUG ((EFI_D_INFO, "(FRM) AcpiRsdp - %016lx\n", mCommunicationData.AcpiRsdp)); DEBUG ((EFI_D_INFO, "(FRM) SmMonitorService - %016lx\n", mCommunicationData.SmMonitorServiceProtocol)); DEBUG ((EFI_D_INFO, "(FRM) SmMonitorBase - %016lx\n", mCommunicationData.SmMonitorServiceImageBase)); DEBUG ((EFI_D_INFO, "(FRM) SmMonitorSize - %016lx\n", mCommunicationData.SmMonitorServiceImageSize)); mHostContextCommon.ImageBase = mCommunicationData.ImageBase; mHostContextCommon.ImageSize = mCommunicationData.ImageSize; // // Prepare heap, then we can use memory service // InitHeap (); // after that we can use mHostContextCommon InitializeSpinLock (&mHostContextCommon.DebugLock); // after that we can use AcquireSpinLock/ReleaseSpinLock (&mHostContextCommon.DebugLock) to control block level debug. InitializeSpinLock (&mHostContextCommon.MemoryLock); // after that we can use MemoryServices InitBasicContext (); InitHostContext (); InitGuestContext (); LauchGuest (); mAlreadyEntered = TRUE; if (InterruptEnabled) { EnableInterrupts(); } return RETURN_SUCCESS; }
int main() { SimpleHeap aHeap; SimpleList elements; long input, i; double key; long *element; tHeapElement *extractedElement; char strInp[256]; InitHeap(&aHeap, 10); while (1) { printf("1. Add element.\n"); printf("2. Extract min element.\n"); printf("3. Extract element at index.\n"); printf("4. Exit.\n"); scanf("%ld", &input); if (input == 4) { break; } if (1 == input) { printf("Enter element key:\n"); scanf("%lf", &key); printf("Enter element itself (long number):\n"); scanf("%ld", &input); element = malloc(sizeof(long)); if (!element) printf("element error\n"); *element = input; if (!AddElementToHeap(&aHeap, key, element, NULL)) printf("Added new element successfully\n"); else { printf("Failed to add element, probably memory problems...\n"); break; } } else if (2 == input) { printf("Extracting min element...\n"); extractedElement = ExtractMinElement(&aHeap, NULL); if (extractedElement) { printf("Element key:%lf, element itself:%ld.\n", extractedElement->key, *(long*) extractedElement->element); free(extractedElement->element); free(extractedElement); } else printf("No elements in heap.\n"); } else if (3 == input) { printf("Enter element index:\n"); scanf("%ld", &input); extractedElement = PopHeapElementAtIndex(&aHeap, input, NULL); if (!extractedElement) printf("Index out of bounds.\n"); else { printf("Element key:%lf, element itself:%ld\n", extractedElement->key, *(long*) extractedElement->element); free(extractedElement->element); free(extractedElement); } } printf("Current heap keys:\n"); elements = aHeap.elements; for (i = 0; i < elements.currentNum; ++i) printf("%lf ", ((tHeapElement*)GetElementAt(&elements, i))->key); printf("\n"); } DisposeHeapWithElements(&aHeap); return 0; }
void FMTK_StartApp(AppStartupRec *asr) { int mapno, omapno; int ret; ACB *pACB; __int32 *pScrn; int *pStack; int ncpages, ndpages, nhpages, nspages, nn; int page; int *p; __int32 *pCode; int *pData; int ndx; int info; try { mapno = mmu_AllocateMap(); if (mapno==-1) return (E_NoMoreACBs); if ((ret = mmu_SetAccessKey(mapno))!=E_Ok) return (ret); // Allocate a page for the ACB pACB = mmu_Alloc8kPage(); // Keep track of the physical address of the ACB ACBPtrs[mapno] = pACB; mmu_SetMapEntry(pACB,MMU_RW|0x10,0); pACB->magic = ACB_MAGIC; pACB->garbage_list = null; // Setup text video pScrn = (__int32 *)(mmu_Alloc8kPage() << 13); mmu_SetMapEntry(pScrn,MMU_RW|0x10,1023); pScrn = (__int32 *)(mmu_Alloc8kPage() << 13); mmu_SetMapEntry(pScrn,MMU_RW|0x8,1022); pScrn = (__int32 *)(mmu_Alloc8kPage() << 13); mmu_SetMapEntry(pScrn,MMU_RW|0x8,1021); pScrn = (__int32 *)(mmu_Alloc8kPage() << 13); mmu_SetMapEntry(pScrn,MMU_RW|0x8,1020); pACB->pVidMem = (__int32 *)(1020 << 13); pACB->pVirtVidMem = (__int32 *)(1020 << 13); pACB->VideoRows = 50; pACB->VideoCols = 80; pACB->CursorRow = 0; pACB->CursorCol = 0; pACB->NormAttr = 0x87fc00; pStack = (int *)(mmu_alloc8kPage() << 13); mmu_SetMapEntry(pStack,MMU_RW|0x8,1019); // Allocate storage space for code ncpages = (asr->codesize+8191) >> 13; ndx = 0; for (nn = 0; nn < ncpages; nn++) { page = mmu_Alloc8kPage(); p = (int *)(page << 13); memcpy(p, &asr->pCode[ndx], 8192); mmu_SetMapEntry(p,MMU_EX|0x8,nn+1); ndx += 2048; } mmu_SetMapEntry(p,MMU_EX|0x10,nn+1); pCode = (__int32 *)(1 << 13); // Allocate storage space for initialized data // and copy from start-up record ndpages = (asr->datasize+8191) >> 13; ndx = 0; for (nn = 0; nn < ndpages; nn++) { page = mmu_Alloc8kPage(); p = (int *)(page << 13); memcpy(p, &asr->pData[ndx], 8192); mmu_SetMapEntry(p,MMU_EX|0x8,nn+1+ncpages); ndx += 1024; } mmu_SetMapEntry(p,MMU_EX|0x10,nn+1+ncpages); pData = (__int32 *)((1+ncpages) << 13); // Allocate storage space for heap nhpages = (asr->heapsize+8191) >> 13; for (nn = 0; nn < nhpages; nn++) { page = mmu_Alloc8kPage(); p = (int *)(page << 13); mmu_SetMapEntry(p,MMU_EX|0x8,nn+1+ndpages+ncpages); } mmu_SetMapEntry(p,MMU_EX|0x10,nn+1+ndpages+ncpages); pACB->pHeap = (MBLK *)((1+ndpages+ncpages) << 13); pACB->HeapSize = (((asr->heapsize + 8191) >> 13) << 13); omapno = mmu_SetOperateKey(mapno); InitHeap(pACB->pHeap, nhpages << 13); mmu_SetOperateKey(omapno); // Allocate storage space for stack nspages = (asr->stacksize+8191) >> 13; for (nn = 0; nn < nspages; nn++) { page = mmu_Alloc8kPage(); p = (int *)(page << 13); mmu_SetMapEntry(p,MMU_EX|(nn==0?0x10:0x8),1019-nn); } pStack = (int *)((1020-nspages) << 13); // Start the startup thread info = (asr->priority << 48) | (mapno << 32) | asr->affinity; FMTK_StartThread( pCode, // start address nspages << 13, pStack, // pointer to stack memory &pACB->commandLine, // parameter info ); } catch(int er) { return (er); } }
void UpdateHeap(DATA dataArray[], uint length){ InitHeap(dataArray, length); }
void Yap_InitMemory(UInt Trail, UInt Heap, UInt Stack) { InitHeap(); }